XPath:仅基于 text() 获取以下兄弟姐妹 [英] XPath: Get following-sibling based on text() only
问题描述
使用相对XPath
和Selenium
,有没有办法获取following-sibling
的文本内容,使用两者的文本内容兄弟姐妹指导?
Using relative XPath
with Selenium
, is there a way to get the text contents of following-sibling
, using the text contents of both siblings as guidance?
<table class="table">
<tbody>
<tr>
<td>Looking for</td>
<td class="text-right">This!</td>
</tr>
</tbody>
</table>
在上面的例子中,我想根据文本Looking for
检索文本片段This!
.
In the above example, I want to retreive the text snippet This!
based on the text Looking for
.
路径必须相对,因为这些表格单元格可以出现在页面的任何位置.以上是完整网页的剪裁.也可以在同一个 The path needs to be relative in the sense that these table cells can appear anywhere on the page. The above is a cut-out of the full web page. There can also be other things inserted before inside the same 我试过这个似乎找到了第一个单元格: I have tried this which seems to find the first cell: 但是,我正在苦苦思索如何在 2nd 兄弟姐妹中获取文本. However, I'm struggling with how to proceed to get the text in the 2nd sibling. 我的尝试看起来像(错误地): My attempt has looked something like (incorrectly): 您几乎做对了,开始吧,您只需要显示您想要查找的确切位置.我希望这会有所帮助: You almost got it right, here you go, you just needed to show where exactly you want to look for. I hope this helps: 这篇关于XPath:仅基于 text() 获取以下兄弟姐妹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! 块之前插入其他内容.
<tr>
block.//text()[contains(.,'Looking for')]
//text()[contains(.,'Looking for')]/following-sibling::text()
推荐答案
//td[text()="Looking for"]/following-sibling::td[text()="This!"]
登录
关闭