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’) 多個路徑查找

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM