Xpath 和innerHTML

发布于 2024-08-31 11:30:41 字数 142 浏览 0 评论 0原文

我可以使用什么 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦里的微风 2024-09-07 11:30:41

不,这是不正确的。 innerHTML 是一个属性,是对象模型的一部分,而 XPath 则对标签和属性进行操作。除非您的 a 标记实际上具有名为 innerHTML 的属性,否则这是行不通的。

如果你想比较标签本身的值,你可以使用 . (点)来引用标签:

a[.='Logout']

但是,我必须添加,以防万一你使用 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 your a tag actually has an attribute named innerHTML, 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:

a[.='Logout']

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文