8

我想使用 xpath 来选择一个链接,其class="watchListItem",span="icon icon_checked"h3="a test". 我可以使用 xpath 来获取匹配的链接和跨度,或者链接和 h3,但不能使用链接、跨度和 h3。

这是我尝试过的:

//*[@class = 'watchListItem']/span[@class = 'icon icon_checked']

//*[@class= 'watchListItem']/h3[text()='AA']

我正在寻找这样的东西:

//*[@class = 'watchListItem']//*[span[@class = 'icon icon_checked'] and h3[text()='AA']]

<li>
<a class="watchListItem" data-id="thisid1" href="javascript:void(0);">
<span class="icon icon_checked"/>
<h3 class="itemList_heading">a test</h3>
</a>
</li>

<li>
<a class="watchListItem" data-id="thisid2" href="javascript:void(0);">
<span class="icon icon_unchecked"/>
<h3 class="itemList_heading">another test</h3>
</a>
</li>

<li>
<a class="watchListItem" data-id="thisid3" href="javascript:void(0);">
<span class="icon icon_checked"/>
<h3 class="itemList_heading">yet another test</h3>
</a>
</li>
4

1 回答 1

9

您可以child::像这样使用位置路径:

//a[@class="watchListItem"
    and child::span[@class="icon icon_checked"]
    and child::h3[text()="another test"]]

这将选择带有 的锚点data-id="thisid3"

于 2013-03-28T15:53:52.133 回答