参考书籍 《selenium2 python自动化测试》-虫师
2017-12-21 本文已影响0人
Future石
元素定位
1、id ,name , class , xpath , css_selector,link_text(),partial_link_text,
2、定于一组元素,比如批量操作
inputs = find_elements_by_('')
for I in inputs:
if i.get_attribute("name") == "技师":
i.click()
3、层级定位注意和相对路径区分
find_element_by_('').find_element_by_("").click()
4、对话框处理
driver.find_element_by_name("password").send_keys("password")
5、多窗口处理
current = driver.current_window_handle. # 获取当前的窗口的句柄
all = driver.window_handles。#获取所有窗口的句柄
for one in all:
if one != current:
driver.switch_to_window(current) # 切换到current对应的窗口
close() # 关闭当前窗口
quit() #推出驱动关闭所有相关窗口
2、获取元素的特征值
input = find_element_by_('')
a = input.get_attribute("name")
3、获取元素对应的标签的文本信息
input = find_element_by_('').text