Xpath关键字ends-with无法使用的问题
在Xpath定位中如果希望使用ends-with会发现不支持的问题,答案如下:
The ends-with
function is part of xpath 2.0 but browsers (you indicate you're testing with chrome) generally only support 1.0. So you'll have to implement it yourself with a combination of string-length
, substring
and equals
substring(@id, string-length(@id) - string-length('register') +1) = 'register'

https://stackoverflow.com/questions/22436789/xpath-ends-with-does-not-work
那么还有那些Xpath定位可以用的呢?
contains、starts-with、*ends-with、text()、and、or、not
//a[contains(text(),"下一页")]或//a[text()='百度搜索']
//input[@type='submit' and @name='calc']
//input[starts-with(@id,'calc')]
//input[not(@type="input")]
ends-with不匹配可以使用
//input[substring(@type, string-length(@type) - string-length('t') +1) = 't']
除此之外还有,选取若干路径
通过在路径表达式中使用"|"运算符,您可以选取若干个路径。
//book/title | //book/price选取 book 元素的所有 title 和 price 元素。
然而Xpath写的再好也不如CSS选择器来的香啊!
长
按
关
注
TestOps公众号
微信号 :TestOps
新浪微博:@TestOps官方微博
知乎:TestOps-云层