Xpath 和innerHTML
我可以使用什么 Xpath 表达式来查找实际文本(innerHTML)为 Logout 的所有锚点(只是“a”)元素。
像这样
//a[@innerHTML='Logout']
正确吗?
What Xpath expression can I use to find all the anchor (just 'a') elements whose actual text (the innerHTML) is Logout.
something like
//a[@innerHTML='Logout']
Would that be correct?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,这是不正确的。
innerHTML
是一个属性,是对象模型的一部分,而 XPath 则对标签和属性进行操作。除非您的a
标记实际上具有名为innerHTML
的属性,否则这是行不通的。如果你想比较标签本身的值,你可以使用
.
(点)来引用标签:但是,我必须添加,以防万一你使用 jQuery:我'我不确定它是否适用于 jQuery。 jQuery 不完全支持 XPath,仅支持基本功能。
No, it would be incorrect.
innerHTML
is a property, part of the object model, while XPath operates on tags and attributes. Unless youra
tag actually has an attribute namedinnerHTML
, this wouldn't work.If you want to compare the value of the tag itself, you can use the
.
(dot) to refer to the tag:However, I must add, just in case you're using jQuery: I'm not sure if it will work with jQuery. jQuery does not support XPath fully, only basic stuff.