title: Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element does not exist in cache
body: <p>I'm receiving <code>StaleElementReferenceException</code> when I'm trying to click an element with in a loop. Following is the code:</p>
  
  <pre><code>WebDriver driver=new ChromeDriver();
  driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
  driver.manage().window().maximize();
  
  driver.navigate().to("URL");
  WebElement Links=driver.findElement(By.xpath("//*[@id='chromemenu']"));
  List &lt;WebElement&gt; AllLinks=Links.findElements(By.tagName("a"));
  System.out.println(AllLinks.size());
  //String start_xpath="//*[@id='chromemenu']/ul/li[";     
  //String end_xpath="]/a";
  
  for(int i=1;i&lt;AllLinks.size();i++)
  {
      System.out.println(AllLinks.get(i).getText());
      System.out.println(AllLinks.get(i).getAttribute("href"));
      //AllLinks.get(i).click();
          //This is where i am clicking  approach 1
      //driver.findElement(By.xpath(start_xpath+i+end_xpath)).click(); 
          //This is where i am clicking  approach 2
      //driver.navigate().back();
  }
  </code></pre>