【发布时间】:2016-05-24 20:37:17
【问题描述】:
在 html 页面中,我有以下应答器:
<button class="....." data-toggle="dropdown">
Text: Title of the button
<span class="....."/>
</button>
我想通过可见文本检测这个按钮 Text: Title of the button 问题是我正在尝试使用以下 Xpath 检测它
.//*[contains(text(),"Text: Title of the button")]
但它不起作用。 我怎样才能检测到这个按钮?
仅供参考:我无法使用 class 检测到它,因为与此类匹配的节点不止一个。
【问题讨论】:
-
试试 //*[contains(text(),"Text: Title of the button")][0] 或分享代码。
-
请查看该文本是否出现在按钮标签内。如果是,请检查文本的部分 //button[contains(text(),'Part of Title of the button')]
-
@IAH2iV 可以看到上面HTML的代码,这个Text是在button标签里面,但是问题是button里面包含了另一个balise。
-
@Kichan Patel,问题不在于 XPATH 有更多匹配节点,而是 XPATH 与任何节点都不匹配。