在html页面中,我具有以下功能:
<button class="....." data-toggle="dropdown">
Text: Title of the button
<span class="....."/>
</button>
我想检测该按钮,通过可见文本Text:按钮的标题,问题是我正尝试使用以下Xpath进行检测
.//*[contains(text(),"Text: Title of the button")]
但这是行不通的。我如何检测到此按钮?
仅供参考:我无法使用来检测到它,class
因为该类有多个匹配的节点。
contains(text(), '...')
仅评估当前上下文元素中的第一个文本节点子级。对于您发布的示例元素,这应该不会有什么问题(请参阅demo,但例如,它不适用于以下元素,因为其中的第一个文本节点button
是位于以下位置的换行符span
:
<button class="....." data-toggle="dropdown">
<span class="....."/>
Text: Title of the button
</button>
要评估当前上下文元素的所有文本节点子代,请改用以下形式:
.//*[text()[contains(.,"Text: Title of the button")]]
上面的XPath测试单个文本节点是否包含某些文本。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句