一、利用WebDriver定位网页元素:
1、find_element_by_id(“kw”)
2、find_element_by_name(“wd”)
3、find_element_by_class_name(“s_ipt”)
4、find_element_by_tag_name(“input”)
5、find_element_by_link_text(“新闻”) 精准匹配
6、find_element_by_partial_link_text(“一个很长的”) 模糊匹配
7、xpath定位
find_element_by_xpath(“/html/body/div/div[2]/div/div/div/from/span/input”) 绝对路径
find_element_by_xpath(“//input[@id=’kw’]”) 元素属性定位 input标签且id是kw
find_element_by_xpath(“//span[@class=’bg s_ipt_wr’]/input”) 层级与属性结合
find_element_by_xpath(“//input[@id=’kw’ and @class=’su’]/span/input”) 使用逻辑运算符
8、css定位
find_element_by_css_selector(“.s_ipt”)通过 .class 属性定位
find_element_by_css_selector(“#kw”)通过 #id 定位
find_element_by_css_selector(“span>input”)通过父子关系定位
find_element_by_css_selector(“[name=’kw’]”)通过属性定位
find_element_by_css_selector(“form.fm>span>input.s_ipt”)通过组合定位
webdriver--Python
最新推荐文章于 2024-03-14 01:34:33 发布