I have this error
Exception in thread "main"
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not linked to the page document
I already look for solutions but none of them helps me to solve my problem or at least that I am implementing it in an erroneous way I would appreciate your help.
This is where the error occurs exactly in suc.selectByIndex (i); As indicated by the stacktrace
public void Descargar()
{
jse = (JavascriptExecutor)driver;
jse.executeScript("scroll(0,300)");
WebElement sucursal_dropdown;
try {
sucursal_dropdown = driver.findElement(By.id("ctl00_PHContenidoPag_ddlRPU"));
sucursal_dropdown.click();
} catch (StaleElementReferenceException e) {
// TODO Auto-generated catch block
sucursal_dropdown = driver.findElement(By.id("ctl00_PHContenidoPag_ddlRPU"));
sucursal_dropdown.click();
e.printStackTrace();
}
Select suc = new Select(sucursal_dropdown);
List<WebElement> list = suc.getOptions();
int total_list = list.size();
System.out.println("List number is "+total_list);
for(int i =0; i<total_list;i++)
{
jse.executeScript("scroll(0,300)");
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
sucursal_dropdown = driver.findElement(By.id("ctl00_PHContenidoPag_ddlRPU"));
suc.selectByIndex(i);
driver.manage().timeouts().pageLoadTimeout(200, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(200, TimeUnit.SECONDS);
jse.executeScript("scroll(0,1300)");
for(int o =2;o<3;o++)
{
driver.findElement(By.id("ctl00_PHMenuIzq_GVHistorial_ctl0"+o+"_DescargaPDF")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
/*driver.findElement(By.id("ctl00_PHMenuIzq_GVHistorial_ctl0"+i+"_DescargaXML")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);*/
}
for(int p =10;p<26;p++)
{
driver.findElement(By.id("ctl00_PHMenuIzq_GVHistorial_ctl"+p+"_DescargaPDF")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
/*driver.findElement(By.id("ctl00_PHMenuIzq_GVHistorial_ctl"+i+"_DescargaXML")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);*/
}
}
}
in advance thank any help.