Danish
Danish

Reputation: 751

webdriver select first sibling based on nth sibling condition

i'm writing a test case in a grid based software I'm mostly using css selectors to select elements and perform clicking

enter image description here

based on the image - I'm selecting the right circled element (base don a css class that displays the blue dot ), now, based on this condition, I want to select the first sibling element - which is a "plus", basically that would open the sub grid further and allow me to run further testing

I can't seem to be able to do that -

assuming that I'm using the following sample html

<div class="td">
    <a class="opener">
    ....
    </a>
</div>
<div class="td">
...
</div>
<div class="td">
...
</div>
<div class="td">
...
</div>
<div class="td">
...
</div>
<div class="td">
    <a class="round-solid">
    ...
    </a>
</div>

I can select "round-solid" - based on this, how do I select "opener" element ?

I only want the opener element for which a specific column contains the "round-solid" class

Upvotes: 0

Views: 293

Answers (1)

ralph.mayr
ralph.mayr

Reputation: 1340

That should do the trick:

driver.findElement(By.xpath("//a[@class='round-solid']/../preceding-sibling::div/a[@class='opener']"));

Upvotes: 1

Related Questions