IndieDev IndieDev - 3 years ago 155
Java Question

Selenium check value of an element's cousin

This is the html structure, keep in mind that there are multiple articles.

<div class="inner-article">
<a style="height:150px;" href="STUFF HERE">
<img width="150" height="150" src="Some more Stuff" alt="Stuff1">
<a class="name-link" href="STUFF"> Item </a>
<a class="name-link" href="STUFF"> Color </a>

How would i find the item of the specified color?

Answer Source

If I understood you correctly, you would like to get anchor tag with heading 1. Use following xpath to find your element

"//a[@class='name-link' and contains(text(),'Y')]/../preceding-sibling::h1/a"

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download