Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xpath-通过匹配两个子节点获取父类_Xpath - Fatal编程技术网

Xpath-通过匹配两个子节点获取父类

Xpath-通过匹配两个子节点获取父类,xpath,Xpath,我想使用xpath选择一个链接,该链接的class=“watchListItem”、span=“icon icon\u”已选中“”和h3=“a test”。我可以使用xpath获取匹配的link和span,或者link和h3,但不能获取link、span和h3 以下是我尝试过的: //*[@class = 'watchListItem']/span[@class = 'icon icon_checked'] //*[@class= 'watchListItem']/h3[text()='AA'

我想使用xpath选择一个链接,该链接的
class=“watchListItem”
span=“icon icon\u”已选中“
”和
h3=“a test”
。我可以使用xpath获取匹配的link和span,或者link和h3,但不能获取link、span和h3

以下是我尝试过的:

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

//*[@class= 'watchListItem']/h3[text()='AA']
我在找这样的东西:

/*[@class='watchListItem']/*[span[@class='icon icon_checked']和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>

  • 您可以使用
    子路径::
    位置路径,如下所示:

    //a[@class=“watchListItem”
    和子项::span[@class=“icon-icon\u-checked”]
    和子项::h3[text()=“另一个测试”]]
    

    这将选择带有
    data id=“thisid3”

    的锚点。我给出了类似的答案,但我使用了
    //span
    而不是
    child::span
    。你知道有什么区别吗?Will
    ::child
    只选择直接子代还是选择任何子代?这在本案中并不重要。只是好奇。::后代会这样做,::子代应该只选择直接子代:)@Ben@Ben但是//将选择子代,而不仅仅是子代。