Thursday, 18 May 2017

xpath going up to parent then back down to child

    <div class="classA">
        <label class="classB">
            <span>Referral Date</span>
        </label>
        <div>
            <input class="classC">
        </div>
     </div>

I'm using xpath to grab by 'Referral Date'. This is a requirement, as user will be passing this human readable label to me. I know how to get there:

    //div/label[@class="classB"]/span[text()="Referral Date"]

Now, I need to access input[@class="classC"] in order to click on it in my WebDriver Automation. Can I do something like this?

    //div/label[@class="classB"]/span[text()="Referral Date"]
    /parent::div/div/input[@class="classC"]

Well, this didn't work for me.

I also tried this without success:

    //div/label[@class="classB"]/span[text()="Referral Date"]
    /following-sibling::div/input[@class="classC"]

Didn't work, and I don't think it can because following sibling only refers to nodes within . Right?



via AutomationEngineer3001

No comments:

Post a Comment