On my page, I have 25 Links displayed inside a web table, now i have to traverse all pagination pages, like 1-25, 25-50, 50-75 etc...my specific link text can be in any pagination set, it can be on any page.
<<previous |1 - 25 of 125| next>>
If the link text matches my string, then click otherwise keep on clicking on "next" button until i find the link. Problem is i am getting "org.openqa.selenium.StaleElementReferenceException: stale element reference: stale element not found
as the Webelement is not longer in DOM. I have tried few methods but its not working.
Method 1:
List<WebElement> links = new ArrayList<WebElement>();
links = driver.findElements(By.xpath("//table[contains(@id,'table1')]//tr//a"));
if (links.get(i).getText().equalsIgnoreCase(MatchString)) {
links.get(0).click();
break;
}
driver.findElement(By.linkText("next")).click();
}
Method2:
for (int i = 1; i < links.size(); i++) {
//// links = driver.findElements(By.xpath("//table[contains(@id,'table1')]//tr//a"));
// links = new ArrayList<WebElement>();
// links = driver.findElements(By.tagName("a"));
// driver.navigate().refresh();
//
//
// if (links.get(i).getText().trim().equalsIgnoreCase(MatchString.trim())) {
// links.get(i).click();
// System.out.println("Link is clicked");
// break;
// }
//
// else {
// driver.findElement(By.linkText("next")).click();
//
// }
// }