org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document

0

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.

    
asked by MIke 12.12.2018 в 20:29
source

1 answer

0

You may need to update the variable suc just before using it with the variable sucursal_dropdown . When you initialize variable suc you initialize it, but then when you use it you do not update it again with the value of branch_dropdown:

sucursal_dropdown = driver.findElement(By.id("ctl00_PHContenidoPag_ddlRPU"));
// Aqui yo actualizaria el select que quieres usar
suc = new Select(sucursal_dropdown);
suc.selectByIndex(i);
    
answered by 15.01.2019 в 13:59