【发布时间】:2013-04-01 18:51:43
【问题描述】:
我需要使用 xpath 选择符合以下三个条件的链接:
父 @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>
【问题讨论】:
-
多种解决方案,您可能遇到的一些问题可能源于文本实际上以换行符开头并以换行符结尾。您可能想使用
contains()或normalize-space()。
标签: xpath