I am working on clicking on the navigation links(marked as 1,2,...Next) for a particular search in the site dice.com
When I run the below mentioned code, it is executed once and then displays StaleElementReferenceException
Request you to help in resolving this issue
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Ex2 {
public static void main(String[] args) {
WebDriver driver=new FirefoxDriver();
driver.get("http://dice.com");
driver.findElement(By.xpath("//input[@id='FREE_TEXT']")).sendKeys("Selenium");
driver. findElement(By.xpath("//*[@id='searchSubmit']")).click();
//block that has navigation links
WebElement b=driver.findElement(By.xpath("//*[@id='yui-main']/div/div[1]/div[1]/div[1][@class='pageProg']"));
//navigation links
List<WebElement> allLinks=b.findElements(By.tagName("a"));
System.out.println("Total links -->" + allLinks.size());
for(int i=0;i<allLinks.size();i++){
allLinks.get(i).click();
Thread.sleep(5000);
}
}
}
The error displayed is
Exception in thread "main" org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up Command duration or timeout: 59 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/stale_element_reference.html Build info: version: '2.35.0', revision: '8df0c6b', time: '2013-08-12 15:43:19' System info: os.name: 'Windows 8', os.arch: 'amd64', os.version: '6.2', java.version: '1.7.0_11' Session ID: 0410f597-c149-46b5-a2b7-e84c61cc73f1