Como lidar com StaleElementReferenceException
Estou trabalhando para passar o mouse e quero testar todas as condições de funcionamento dos links clicando em cada link usando o loop for.No meu programa, a iteração está ocorrendo uma vez e, na próxima iteração, não está funcionando e mostrando a "StaleElementReferenceException" .......... Por favor, modifique o código, se necessário ....
public static void main(String[] args) throws IOException
{
WebDriver driver = new FirefoxDriver();
Autoit.Authenti(driver);
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.get("http://staging.zenrays.com");
Actions a1=new Actions(driver);
WebElement cl=driver.findElement(By.xpath(".//*[@id='menu-450-2']/a"));
a1.moveToElement(cl).perform();
WebDriverWait wait =new WebDriverWait(driver, 30);
List<WebElement> links=driver.findElements(By.xpath("//a[contains(@class,'sf-depth-2')]"));
for(int i=0;i<=links.size()-1;i++)
{
links.get(i).click();
driver.navigate().back();
}
}
}