First off, I am a Javascript developer tasked with dealing with Selenium, and I feel the pain QE goes through now lol, so my knowledge of Java is basic. I have the following DOM structure and I need to be able to find "Link Name 1" and click it. I will also have to do the same for the other links in different tests.
<div class="some-container">
<div class="blah"></div>
<div>
<div>
<div class="common-class-name">
<a>Link Name 1</a>
</div>
</div>
<div>
<div class="common-class-name">
<a>Link Name 2</a>
</div>
</div>
<div>
<div class="common-class-name">
<a>Link Name 3</a>
</div>
</div>
</div>
</div>
<div class="some-other-container">
<div class="blah"></div>
<div>
<div>
<div class="common-class-name">
<a>Link Name 1</a>
</div>
</div>
<div>
<div class="common-class-name">
<a>Link Name 2</a>
</div>
</div>
<div>
<div class="common-class-name">
<a>Link Name 3</a>
</div>
</div>
</div>
</div>
Here is one of the things I have tried, the findElementsWithWait is basically a utility function that uses findElements with a wait. This does not work.
List<WebElement> list = findElementsWithWait(By.className("common-class-name"));
for (WebElement element: list) {
WebElement el = element.findElement(By.tagName("a"));
String text = el.getText();
// other code would check for the proper text and click...
}
What is the best way to get the list of a tags to be able to click them based on text value?