0

I keep getting an error message in my selenium java project.

for(WebElement link:AllTheLinkList) {
    if (link.getAttribute("href") != null
        && ! link.getAttribute("href").contentEquals("javascript"))
    {
        activeLinks.add(link);
    }
}

// Get total amount of links in the page
System.out.println("Size of active links and images --->"
                 + activeLinks.size()); 

Error message is:

Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

j.barrio
  • 1,006
  • 1
  • 13
  • 37
SanjX
  • 957
  • 1
  • 8
  • 12

1 Answers1

0

The problem usually is that the page, where you are obtaining the links, is refreshed during your loop. An option to solve that is obtain a list of strings with the href values and after start the loop, all the objects are Strings and that doesn't change.

In another hand, you can do a loop with a numeric iterator, and the last instruction before the next loop iteration could be obtain again the AllTheLinkList.

j.barrio
  • 1,006
  • 1
  • 13
  • 37