Python自动化中的元素定位xpath(二)

1、Xpath元素定位

1)ele = b.find_element_by_xpath(‘/html/body/from/input[1]’)

2)Ele = b.find_element_by_xpath(‘//input[2]’) 定位第二个input

3)Ele = b.find_element_by_xpath(‘//from//input’) 定位from里面的input

4)Ele = b.find_element_by_xpath(‘//input[@id]’) 定位input里面含有id

5)Ele = b.find_element_by_xpath(‘//input[@name=”firstname”]’)

6)Ele = b.find_element_by_xpath(‘//*[count(input)=2]’) 定位具有两个input的元素(*为所有元素)

7)Ele = b.find_element_by_xpath(‘//*[count(input)=2/..]’)定位具有两个input的元素的父节点

8)Ele = b.find_element_by_xpath(‘//*[local-name()=”input”]’)定位标签为input的元素

9)Ele.tag_name      显示定位的标签名称

10)ele.get_attribute(‘name’) 显示定位到的属性名称

11)Ele = b.find_element_by_xpath(‘//*[starts-with(local-name(),”i”)]’)定位所有tagi开头的元素

12)Ele = b.find_element_by_xpath(‘//*[contains(local-name(),”i”)]’)定位所有tag包含i的元素

13)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)]’)定位在from里面所有tag包含i的元素

14)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)][last()]’)定位在from里面所有tag包最后一个含i的元素

15)Ele = b.find_element_by_xpath(‘//from//*[contains(local-name(),”i”)][last()-1]’)定位在from里面所有tag包倒数第二个含i的元素

16)Ele = b.find_element_by_xpath(‘//*[string-length(local-name())=5]’)定位所有tag里面长度为5的元素

17)Ele = b.find_element_by_xpath(‘//title | //input’) 多个路径查找

原文地址:https://www.cnblogs.com/yanmou/p/10678075.html