Xpath:选择匹配三个子属性的父链接

时间:2013-04-01 18:51:44

标签: xpath

我需要使用符合以下三个标准的xpath选择一个链接:

parent @class ='testItem'

child @class ='icon icon_checked'

text ='测试文字在这里!'

我不确定将text属性放在xpath引用中的位置。我尝试过以下几种排列方式:

//a[@class="testItem" and child::span[@class="icon icon_checked"] and li[text()="test text goes here!"]]

我的问题是文本部分不在其自己的范围内。

这是原始示例:

<li>
<a class="testItem2" data-code="2" href="javascript:void(0);">
<span class="icon icon_checked"></span>
test text goes here2!
</a>
</li>

<li>
<a class="testItem" data-code="2" href="javascript:void(0);">
<span class="icon icon_checked"></span>
test text goes here!
</a>
</li>

1 个答案:

答案 0 :(得分:1)

感谢您的帮助。我找到了答案。

我可以简单地将xpath的最后一部分从li [text()=“test text goes here!”]更改为。[text()=“test text goes here!”]。

我最后的工作xpath是:

//a[@class='testItem' and child::span[@class='icon icon_checked'] and .[text()='test text goes here!']]
相关问题