仅当另一个孩子在场时,Xpath才会在父母身上找到孩子

时间:2017-02-14 13:49:33

标签: html xpath

所以我有一个网页,只有当div entire class中存在按钮 NameField 时,我才想找到按钮 SignUp

<div class="entire class">
    <div class = "upper class>
        <button class="NameField"></button>
    </div>
    <div class="lower class">
        <button class="SignUp"></button>
    </div>
</div>

我将如何实现这一目标?我尝试过以下方法:

$x("//div[@class='entire class']//button[@class='NameField'] and not(descendant::button[@class='SignUp']")

$x("//*[@class='upper class'] | [@class='SignUp']")

$x("//*[@class='SignUp'] | //body)[last()]")

$x("//div[//button[@class='SignUp'] and [//button[@class='NameField']]")

他们似乎都没有工作。

1 个答案:

答案 0 :(得分:1)

请尝试以下//div[button[@class="NameField"]]/following-sibling::div/button[@class="SignUp"] //div[@class="entire class" and div[button[@class="NameField"]]]/div/button[@class="SignUp"]

//button[@class="NameField"]/following::button

或简化的:

{{1}}