0

I am trying to click the main menu items in seleniumhq.org but after clicking on the first link i am getting a StaleElementReferenceException:Element not found in the cache=perhaps the page was changed since it was looked up

Please provide solution to solve the above problem

Below was my code

    WebDriver  d=new FirefoxDriver();
    d.get("http://docs.seleniumhq.org/");
    d.manage().timeouts().implicitlyWait(100,TimeUnit.SECONDS); 
    List<WebElement> l=d.findElements(By.cssSelector("ul>li"));
    for(WebElement e:l) {
    e.click();      
    }

Thanks in advance

user3660822
  • 33
  • 1
  • 6

1 Answers1

0

If you click on a link and you are taken to the different page or even if you stay in same page the DOM is refreshed. Those elements are not attached to DOM anymore. You need to write some code to come back to previous page if your click takes you to a different page or even if you stays in same page you have find the link on the fly to click instead of "e.click()"

Saifur
  • 16,081
  • 6
  • 49
  • 73