打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Xpath关键字ends-with无法使用的问题

在Xpath定位中如果希望使用ends-with会发现不支持的问题,答案如下

The ends-withfunction 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-lengthsubstringand 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-云层

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
代码练习:简单的纯文本转HTML
1446. Consecutive Characters (E)
iOS文本输入过滤 emoji 表情符号
根相对路径转换成当前相对路径 - 林子之大.net笔记 - 博客园
使用Xpath获取页面元素
js-六爻排盘
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服