| 定位方式 | xpath | CSS | |
| 常規屬性 | id | //*[@id='kw'] | #kw |
| class | //input[@class='s_ipt'] | .s_ipt | |
| name | //input[@name='wd'] | [name='wd'] | |
| 其他屬性 | 其他屬性 | //input[@autocomplete='off'] | [autocomplete='off'] |
| 多個屬性組合(邏輯運算) | //input[@type='text'and @name='wd'] | [type='text'][name='wd'] | |
| 文本屬性 | //*[text()='文本內容'] | ||
| 層級關系 | 相對路徑 | //form[@id='form]/span/input | form#form>span>input |
| 索引 | //select[@id='nr']/option[3] | select#nr>option:nth-child(3) | |
| select#nr>option:eq(2) | |||
| select#nr>option:first | |||
| select#nr>option:last | |||
| 通過兒子找父親 | 兩個點代表父級 | //*[@id='']/../.. | |
| 模糊匹配 | 模糊匹配text | //*[contains(text(),'糯米')] | |
| 模糊匹配某個屬性 | //*[contains(@class,'s_ip')] | ||
| 模糊匹配以xx開頭 | //*[starts-with(@id,'xx')] |
轉自:https://www.cnblogs.com/anthinia/p/10735877.html
