Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Xml XPath:仅基于text()获取以下同级_Xml_Selenium_Xpath - Fatal编程技术网

Xml XPath:仅基于text()获取以下同级

Xml XPath:仅基于text()获取以下同级,xml,selenium,xpath,Xml,Selenium,Xpath,将相对XPath与Selenium一起使用,是否有一种方法可以使用两个同级的文本内容作为指导,获取同级的的文本内容 <table class="table"> <tbody> <tr> <td>Looking for</td> <td class="text-right">This!</td> </tr>

将相对
XPath
Selenium
一起使用,是否有一种方法可以使用两个同级的文本内容作为指导,获取同级的
的文本内容

<table class="table">
    <tbody>
        <tr>
            <td>Looking for</td>
            <td class="text-right">This!</td>
        </tr>
    </tbody>
</table>

寻找
这
在上面的示例中,我想检索文本片段
This基于文本
查找

路径必须是相对的,因为这些表格单元格可以出现在页面的任何位置。以上是整个网页的剪贴。在同一
块中还可以插入其他内容

我试过这个,似乎找到了第一个单元格:

//text()[包含(,'Looking')]

然而,我正在为如何继续获取第二兄弟姐妹中的文本而挣扎

我的尝试看起来像(错误的):


//text()[包含(,'Looking')]/following sibling::text()

您几乎成功了,现在,您只需要显示您要查找的确切位置。我希望这有助于:

//td[text()="Looking for"]/following-sibling::td[text()="This!"]
你可以用

//td[contains(text(),'Looking for')]//following-sibling::td[contains(text(),'This!')]

有关兄弟姐妹和祖先的更多参考信息,您还可以使用以下内容查找第二兄弟姐妹:

//table[@class='table']/descendant::td[last()]
要查找第一个兄弟姐妹,可以使用以下命令:

//table[@class='table']/descendant::td[last()-1]

谢谢就像一个符咒。@Winterflags,对你也是:)