Hi I'm using selenium on Java and here's the situation:
<article>
<div class="inner-article">
<a style="height:150px;" href="link">
<img width="150" height="150" src="//somelink.jpg" alt="Qxvd 81gof8" />
</a>
<h1>
<a class="name-link" href="something">THE NAME I"M USING TO FIND THIS ELEMENT
</a>
</h1>
<p>
<a class="name-link" href="somelink">Colour1</a>
</p>
</div>
</article>
<article>
<div class="inner-article">
<a style="height:150px;" href="somelink">
<img width="150" height="150" src="someotherlink.jpg" alt="S83glqvbtt8" />
</a>
<h1>
<a class="name-link" href="link">THE SAME NAME I"M USING</a>
</h1>
<p>
<a class="name-link" href="">Colour2</a>
</p>
</div>
</article>
What I want to do is to click on the item with colour2 in it. For now I'm just clicking on the first item on the site by searching for the name of element "THE NAME I"M USING TO FIND THIS ELEMENT".
driver.findElement(By.xpath("//*[text()[contains(., 'THE NAME I"M USING TO FIND THIS ELEMENT')]]")).click();
Also wanted to add that there's more elements containing "colour 2" on the site so I need something that will find "colour2" by will start searching from ">THE SAME NAME I"M USING" element