I'm getting stale element exception and tried adding try catch block but still i'm getting this error. Is there a way to resolve it? I want to click on particular link in each div which contains the text "Dep. Libraries".
List<WebElement> lib = driver.findElements(By.className("row"));
ListIterator<WebElement> listlib = lib.listIterator();
System.out.println(listlib);
while(listlib.hasNext()) {
WebElement elem = listlib.next();
List<WebElement> sub = elem.findElements(By.cssSelector("div[class='column sp']"));
ListIterator<WebElement> listsub = sub.listIterator();
while(listsub.hasNext()) {
WebElement elem1 = listsub.next();
if((elem1.getText()).contains("Dep. Libraries")) {
elem1.click();
break;
}
}
}