Selenium-Webdriver(python) (九) --- 操作对象
2013-12-10 19:37
483 查看
webdriver中较常用的操作对象的方法如下:
· click 点击对象
· send_keys 在对象上模拟按键输
· clear 清除输入框默认显示的内容
· text 获取该元素的文本
· submit 提交表单
· get_attribute 获得属性值
click、send_keys、clear比较常用就不举例了,text、submit、get_attribute如下:
1.获取元素文本并打印文本
data=driver.find_element_by_link_text(u"用户注册").text #定位元素位置并获取文本信息
print data #打印信息
2. submit 提交表单 相当于click操作:
driver.find_element_by_id("WG_submit").submit()
select = driver.find_element_by_tag_name("select")
allOptions = select.find_elements_by_tag_name("option")
for option in allOptions:
print "Value is:" + option.get_attribute("value")
option.click()
· click 点击对象
· send_keys 在对象上模拟按键输
· clear 清除输入框默认显示的内容
· text 获取该元素的文本
· submit 提交表单
· get_attribute 获得属性值
click、send_keys、clear比较常用就不举例了,text、submit、get_attribute如下:
1.获取元素文本并打印文本
data=driver.find_element_by_link_text(u"用户注册").text #定位元素位置并获取文本信息
print data #打印信息
2. submit 提交表单 相当于click操作:
driver.find_element_by_id("WG_submit").submit()
相当于:
driver.find_element_by_id("WG_submit").click()
3.get_attribute获得属性值。定位一组元素的时候较常用
select = driver.find_element_by_tag_name("select")
allOptions = select.find_elements_by_tag_name("option")
for option in allOptions:
print "Value is:" + option.get_attribute("value")
option.click()
相关文章推荐
- python selenium-webdriver 元素操作之鼠标操作(四)
- selenium webdriver+python的基本操作
- python + selenium webdriver 通过python来模拟鼠标、键盘操作,来解决SWFFileUpload调用系统底层弹出框无法定位问题
- 转:selenium webdriver+python基本操作
- python selenium-webdriver 元素操作之键盘操作
- selenium webdriver python 操作IE浏览器
- python selenium-webdriver 常用浏览器的操作 (十)
- Selenium Webdriver API-Robot对象操作键盘
- selenium webdriver python 操作浏览器
- python selenium-webdriver 元素操作之键盘操作(五)
- selenium python webdriver 操作页面的滚动条
- selenium_webdriver(python)文件上传操作
- selenium webdriver python 元素操作
- Selenium WebDriver控制操作(Python)
- selenium webdriver(3)---操作页面对象
- selenium webdriver python 元素操作
- selenium webdriver学习(二)————对浏览器的简单操作
- selenium-webdriver(python)-- 处理下拉框