度过了一个冬眠,在春末夏初之际,补充自己的营养,努力学习,努力工作!

selenium2.0关于python的常用函数(二)

上一篇 / 下一篇  2013-08-09 16:46:12 / 个人分类:selenium

新建实例driver = webdriver.Chrome()
1.获取当前页面的Url函数
方法:current_url
实例:
driver.current_url

G*A0q gCW+i02.获取元素坐标

0i4fW4{$ml0

J;dcs_/@v}(G@p K0方法:location

$E/cM5G| D0

r m/|L8I(_#`/jc yu0解释:首先查找到你要获取元素的,然后调用location方法

4I{q[4x+`C0

4YA/JbT0实例:51Testing软件测试网2@W:C;em o+Bk

51Testing软件测试网"W1O }A_

driver.find_element_by_xpath("//*[@id='tablechart']/tbody/tr[14]/td[9]").location51Testing软件测试网IOe2NWcA1V7CE

51Testing软件测试网 A0U0{^P;|F;n ?

3.表单的提交51Testing软件测试网h9A6ll {*L

51Testing软件测试网7e8x}r/x.Z x$^3\C

方法:submit

gd8m3U]vR k+bBrb0

k"|a0`V'D0解释:查找到表单(from)直接调用submit即可51Testing软件测试网v6@C^kL;B

FY$QAG[z,_0实例:51Testing软件测试网E"l V R5?.x:A3V

51Testing软件测试网}m7l+M8JGH\

driver.find_element_by_id("form1").submit()

A _V@d`051Testing软件测试网{j7h|d#Xh

4.获取CSS的属性值

"A!}|?$c4L0
方法:value_of_css_property(css_name)
实例:
driver.find_element_by_css_selector("input.btn").value_of_css_property("input.btn")
5.获取元素的属性值
方法:get_attribute(element_name)
实例:
driver.find_element_by_id("sellaiyuan").get_attribute("sellaiyuan")
6.判断元素是否被选中
方法:is_selected()
实例:
driver.find_element_by_id("form1").is_selected()
7.返回元素的大小
方法:size
实例:
driver.find_element_by_id("iptPassword").size
返回值:{'width': 250, 'height': 30}
8.判断元素是否显示
方法:is_displayed()
实例:
driver.find_element_by_id("iptPassword").is_displayed()51Testing软件测试网jEFd"k5y9a
9.判断元素是否被使用
方法:is_enabled()
实例:
driver.find_element_by_id("iptPassword").is_enabled()
10.获取元素的文本值
方法:text
实例:driver.find_element_by_id("iptUsername").text
11.元素赋值
方法:send_keys(*values)
实例:
driver.find_element_by_id("iptUsername").send_keys('admin')
注意如果是函数需要增加转义符u,eg.
driver.find_element_by_id("iptUsername").send_keys(u'青春')
12.返回元素的tagName
方法:tag_name
实例:
driver.find_element_by_id("iptUsername").tag_name
13.删除浏览器所以的cookies
方法:delete_all_cookies()
实例:
driver.delete_all_cookies()
14.删除指定的cookie
方法:delete_cookie(name)
实例:deriver.delete_cookie("my_cookie_name")
15.关闭浏览器
方法:close()
实例:driver.close()
16.关闭浏览器并且推出驱动程序
方法:quit()
实例:driver.quit()
17.返回上一页
方法:back()
实例:driver.back()
18.设置等待超时
方法:implicitly_wait(wait_time)
实例:driver.implicitly_wait(30)
19.浏览器窗口最大化
方法:maximize_window()
实例:driver.maximize_window()
20.查看浏览器的名字
方法:name
实例:drvier.name

Rt5TUX4rCJ0以上内容转发自http://blog.sina.com.cn/s/blog_b5fe6b270101c8v0.html
+Vo.rgcU9O5T051Testing软件测试网#\xCt(F.M0K"O


TAG:

 

评分:0

我来说两句

Open Toolbar