XPath:仅根据 text() 获取后续兄弟

Win*_*ags 5 xml selenium xpath

使用relativeXPathSelenium,有没有办法以following-sibling兄弟姐妹的文本内容为指导来获取 的文本内容?

\n\n
<table class="table">\n    <tbody>\n        <tr>\n            <td>Looking for</td>\n            <td\xc2\xa0class="text-right">This!</td>\n        </tr>\n    </tbody>\n</table>\n
Run Code Online (Sandbox Code Playgroud)\n\n

在上面的示例中,我想This!根据text 检索文本片段Looking for

\n\n

该路径需要是相对的,因为这些表格单元格可以出现在页面上的任何位置。上面是完整网页的截图。在同一个块内之前还可以插入其他内容<tr>

\n\n

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

\n\n

//text()[contains(.,\'Looking for\')]

\n\n

但是,我正在努力解决如何继续获取第二个兄弟姐妹中的文本。

\n\n

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

\n\n

//text()[contains(.,\'Looking for\')]/following-sibling::text()

\n

New*_*mer 5

您几乎做对了,在这里,您只需要显示您到底想要查找的位置即可。我希望这有帮助:

//td[text()="Looking for"]/following-sibling::td[text()="This!"]
Run Code Online (Sandbox Code Playgroud)