0

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;
                }
             }
        }
    

1 Answers1

0

There are 2 ways to resolve stale element error

  1. Refresh page before interect element (Use Refresh();)
  2. Try to loop until the particular element capture
Justin Lambert
  • 940
  • 1
  • 7
  • 13