How to click on a link that is under a table element, but that is not visible on first page. There are pagination links “previous” & “next” on the page, and i want to iterate over multiple pages and find my link “a” tag based on Link text.
if link matches the string, then only click on the link, otherwise keep clicking “Next” in the pagination.
List<WebElement> links = driver.findElements(By.tagName(“a”));
int size = links.size();
for (int i = 0; i < size; i++) {
if (links.get(i).getText().equalsIgnoreCase(LinkMatchValue)) {
driver.findElement(By.xpath(“//a[contains(text(),'” + LinkMatchValue+ “‘)]”)).click();
} else {
driver.findElement(By.linkText(“next”)).click();
}
}
==================================================================================
<table id=”table1″>
<thead>
<tr>
</td>
</tr><tr class=”classA”>
<td><a href=…”>Link 1</a></td>
</tr>
<td><a href=…”>Link 1</a></td></tr><tr class=”even”>
<td><a href=…”>Link 2</a></td></tr><tr class=”even”>
<td><a href=…”>Link 3</a></td></tr><tr class=”even”>
<td><a href=…”>Link 4</a></td></tr><tr class=”even”>
<td><a href=…”>Link 5</a></td></tr><tr class=”even”>
<td><a href=…”>Link 6</a></td></tr><tr class=”even”>
</tbody>
</table>
Source: Read More