【问题标题】:determining the correct xpath for following sibling确定以下兄弟姐妹的正确 xpath
【发布时间】:2015-10-04 21:43:40
【问题描述】:

我有一些html代码如下。我只展示了适用的部分(之前和之后还有更多的div块,但它们在这里无关)

<div style="display: inline-block; position: absolute; top: 65px; bottom: auto; left: 5px; right: auto; width: auto; height: auto; max-width: none; max-height: none;" _afrc="2 1 6 1 start top">ID1: </div>
<div style="display: inline-block; position: absolute; top: 65px; bottom: auto; left: 89px; right: auto; width: auto; height: auto; max-width: none; max-height: none;" _afrc="3 1 6 1 start top">5134925</div>
<div style="display: inline-block; position: absolute; top: 84px; bottom: auto; left: 5px; right: auto; width: auto; height: auto; max-width: none; max-height: none;" _afrc="2 1 8 1 start top">ID2: </div>
<div style="display: inline-block; position: absolute; top: 84px; bottom: auto; left: 89px; right: auto; width: auto; height: auto; max-width: none; max-height: none;" _afrc="3 1 8 1 start top">1340921</div>

我想获取 ID1 (5134925) 和 ID2 (1340921) 的值,我想我会使用以下兄弟,但我无法从搜索中理解。

我可以使用 "//div[contains(text(),'ID1:')] 和 //div[contains(text(),'ID2:')] 但我需要在之后直接找到 div。我可能会使用以下兄弟,但我不知道语法。有什么建议吗?

【问题讨论】:

  • 顺便说一句,假设一个 div 编号是不可接受的(例如 id2 的值是 //div[4] 因为 div 总是在之前和之后添加。

标签: java html xpath


【解决方案1】:

只需附加following-sibling::div[1]:

//div[contains(text(),'ID1:')]/following-sibling::div[1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-08
    • 2014-03-04
    • 1970-01-01
    相关资源
    最近更新 更多