XPath 是一門在 XML 文檔中查找信息的語言。XPath 可用來在 XML 文檔中對元素和屬性進行遍歷。app
xpath在selenium主要應用於無id,且屬性值不惟一的元素定位。ide
目標:第1行第1列spa
//tbody/tr[1]/td[1]
釋:xpath順序從1開始code
目標:第1行7列編輯按鈕orm
//tbody/tr[1]/td[7]/div/button/span[contains(text(),"編輯")]
//div[@class="el-table__fixed-body-wrapper"]/table/tbody/tr[1]/td[7]/div/span[text()="編輯"] or //tbody[2]/tr[1]/td[7]/div/button/span[contains(text(),"編輯")]
目標:最後1行倒數第二列blog
//tbody/tr[3]/td[6]
當行數、列數不肯定時,隊列
//tbody/tr[last()]/td[last()-1]
1)//*[@id="app"]/section/section/main/div[2]/form/div/div[1]/div/div/div/input
2)//input[@placeholder="請輸入搜索客戶姓名"]
3)//label[text()="姓名"]/following-sibling::div[1]/div/input
ip
//*[@id="app"]/section/section/aside/div/div[2]/div[2] //div[contains(@class,"child") and contains(text(),"團隊列表")]
1)//tbody/tr[1]/td[1]/div/div/span[@class='el-tag el-tag--success el-tag--mini' or @class='el-tag el-tag--mini'] 2)//tbody/tr[1]/td[1]/div/div/span[contains(text(),"發佈")]