看板 Soft_Job 關於我們 聯絡資訊
請教版上大大 有一樹狀結構如下: <div id='wd-Inbox-mainpage'> <div> <div> <ul data-automation-id='inbox_item_list'> 要用XPath來定位到該ul元素,目前有以下幾種寫法都可行 1. .//ul[@data-automation-id='inbox_item_list'] . 2. .//*[@data-automation-id='inbox_item_list'] 3. .//*[@id='wd-Inbox-mainpage']/div[1]/div[1]/ul 4. .//*[@id='wd-Inbox-mainpage']/div[1]/div[1]/ul[@data-automation-id= 'inbox_item_list'] 請問哪種方法能最快找到該元素? 另外使用.//或//對搜尋速度會有影響嗎,哪個較快找到? -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 61.219.237.246 ※ 文章網址: https://www.ptt.cc/bbs/Soft_Job/M.1525748687.A.1DF.html
vi000246: 在chrome的F12 直接按右鍵複製xpath的最快 05/08 11:40
vi000246: 你可以寫個計時器 算算撈一萬次兩種寫法的差別 05/08 11:41
ian90911: 原來chrome f12可以直接抓xpath 學到一招了 05/08 12:04
alog: 其實 element 沒有量其實還好 最終還是要看 library 的實作/ 05/08 12:24
alog: 搜尋方式跟特性 05/08 12:24
alog: 要找就找 ul 跟 data-automation-id 那個就可以了 05/08 12:27
alog: 除非你找的 element 有特別的規則 例如抓要在特定的階層底下 05/08 12:29
alog: 這個東西 其他的忽略 05/08 12:29
alog: 否則應該要將xpath簡化 但回到一開始講的 05/08 12:29
alog: 元素沒破千破萬應該是還好 那個算多少次都一樣 05/08 12:30
FacetheFaith: Chrome抓到的XPath是//*[@id='wd-Inbox-mainpage']/ 05/08 12:34
FacetheFaith: div[1]/div[1]/ul,所以用這個比較好嗎 05/08 12:34
TitanEric: 個人覺得xpath不好懂 我都用selector 05/08 12:38
alog: Google 那個是方便抓 不會有特別優化 05/08 13:00
alog: 只有element 帶有id 才會特別優化 因為 id 搜尋底層會有比 05/08 13:02
alog: 較快的優化處理 05/08 13:02
FacetheFaith: 那id跟data-automation-id哪個比較快?後者是怎麼產 05/08 13:18
FacetheFaith: 生的? 05/08 13:18
alog: id 但是你要找的資料是 帶有data-automation-id 的ul 05/08 13:18
alog: 所以東西簡單處理就好 05/08 13:19
FacetheFaith: 所以會建議選1嗎 05/08 13:21
alog: 嗯 因為你找的類型似乎沒有這麼強調階層之間的關係 05/08 13:22
thekensg: 是關工作版屁事啊 05/08 19:31
ripple0129: 頁面是有這麼多DOM需要考量到效能啊@@其實這個想一下 05/10 00:52
ripple0129: 也知道,第一個比對,id通常只有一個所以可以快速且 05/10 00:52
ripple0129: 正確定位效能一定是最快的 05/10 00:52