Xpath定位和CssSelector定位的區別


1、Xpath基本語法:

(1)"/":從根節點選取,下級節點

(2)"//":任意節點選取

(3)"*":任意標簽選取

(4)"@":選取屬性

(5)"..":選取當前節點的父節點

(6)"text()":匹配節點全部鏈接文字

(7)"contains(a,b)":匹配節點部分鏈接文字

(8)"last()"選取最后一個

2、Xpath與Css Selector的區別:

定位方式 Xpath Css Selector
find_element_by_id("id值") //*[@id="id值"] #id值
find_element_by_name("name值") //*[@name="name值"] [name="name值"]
find_element_by_class_name("某一個class name") 某一個class name .某一個class name
find_element_by_tag_name("標簽名") //標簽名 標簽名
find_element_by_link_text("鏈接文字") //a[text()="鏈接文字"] 不支持
find_element_by_partial_link_text("部分鏈接文字") //a[contains(text(),"部分鏈接文字")] 不支持


免責聲明!

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



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