CSS表达式 | 匹配元素说明 | xpath |
* | 匹配任何元素 | //* |
div | 标签 | //div |
div#eleID | by ID | //div[@id=‘eleID‘] |
div.class | by class | //div[contains(@class,"class")] |
div[title=AB] div[title ^=A] div[title $=A] |
by 属性 =AB 以A开头 以A结尾 |
//div[@title = "AB"] //div[@title ^= "A"] //div[@title $= "A"] |
div #id > * div #id > h1 |
子元素 |
//div[@id="id"] /* //div[@id="id"] /h1 |
div h1 |
定位后代元素 | //div//h1 |
li : hth(5) | by index | //li[6] |
a:contains("abc") | by content | //a[contains(.,"abc")] |
li{a:contains("abc")} ul{a:contaions("abc")} |
根据子元素回溯父元素 |
//li[a[contains(.,"abc")]] //li[./a[contains(.,"abc")]] //ul[.//a[contains(.,"abc")]] |
css=li:contains("abc")+li css=ul{a:contains("abc")}~ul |
根据相邻元素定位 |
//li[preceding-sibling::li[contains(.,"abc")]] //ul[preceding-sibling::ul[.//a[contains(.,"abc")]]] |
div.a.b | 多个类定位 | |
时间: 2024-10-09 18:00:10