title: How to fetch all links and click those links one by one using Selenium WebDriver
body: <p>I am using Selenium WebDriver with java.</p>
  
  <p>I am fetching all links from webpage and trying to click each link one by one. I am getting below  error:</p>
  
  <blockquote>
    <p>error org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
    Command duration or timeout: 30.01 seconds
    For documentation on this error, please visit: <a href="http://seleniumhq.org/exceptions/stale_element_reference.html" rel="nofollow noreferrer">http://seleniumhq.org/exceptions/stale_element_reference.html</a>
    Build info: version: '2.25.0', revision: '17482', time: '2012-07-18 21:09:54'</p>
  </blockquote>
  
  <p>and here is my code :</p>
  
  <pre><code>public void getLinks()throws Exception{
      try {
          List&lt;WebElement&gt; links = driver.findElements(By.tagName("a"));
          int linkcount = links.size(); 
           System.out.println(links.size()); 
            for (WebElement myElement : links){
           String link = myElement.getText(); 
           System.out.println(link);
           System.out.println(myElement);   
          if (link !=""){
               myElement.click();
               Thread.sleep(2000);
               System.out.println("third");
              }
              //Thread.sleep(5000);
            } 
          }catch (Exception e){
              System.out.println("error "+e);
          }
      }
  </code></pre>
  
  <p>actually,  it's displaying in output </p>
  
  <blockquote>
    <p>[[FirefoxDriver: firefox on XP (ce0da229-f77b-4fb8-b017-df517845fa78)] -> tag name: a] </p>
  </blockquote>
  
  <p>as link, I want to eliminate these form result.</p>