Xpath定位常用函数

常用方式

1.//div[contains(@id,'in')]---找到所有id中包含有in的div

2.//a[text()='百度知道']--找到含有文本"百度知道"的超链接

3.//div[starts-with(@id,'in')]--找到所有id以in开头的div,延伸//div[starts-with(text()='百度')]

4.复合函数and--//div[starts-with(@id,'in') and contains(@id,'pu')]--找到所有id中包含有in并且id中包含pu的div

复合函数and--//div[starts-with(@id,'in') or contains(@id,'pu')]--找到所有id中包含有in或者id中包含pu的div

5.//div[not(starts-with(@id,'in'))]--找到所有不是id以in开头的div

Xpath轴:


1.preceding-sibling::--找到当前元素的所有同级元素
eg://a[text()='百度知道']/preceding-sibling::a[1]----找到含有文本"百度知道"的超链接的元素的第一个同级元素a,preceding代表之前的

1.following-sibling::--找到当前元素的所有同级元素
eg://a[text()='百度知道']/following-sibling::a[1]----找到含有文本"百度知道"的超链接的元素的第一个同级元素a,following代表之后的

猜你喜欢

转载自blog.csdn.net/wushuai150831/article/details/79047496