dimanche 2 avril 2017

Selenium StaleElementReferenceException on ajax option select

I´m testing a form with 4 selects . When I select the first one it makes an ajax call depending on the value and populates the next select . But most of the time I´m getting a StaleElementReferenceException . I´m implementing FluentWait and my custom Expected condition to test that the select is populated

I´m using the same FluentWait

FluentWait<WebDriver> wait = new FluentWait<WebDriver>(webdriver).withTimeout(10, TimeUnit.SECONDS)
                .pollingEvery(2, TimeUnit.MILLISECONDS)
                .ignoring(StaleElementReferenceException.class)
                .ignoring(NoSuchElementException.class);

Here is the code that retrieves the webelement , and select the 3rd element.

        WebElement brand= wait.until(ExpectedConditions.elementToBeClickable(By.id("brand")));
        Select selectBrand= new Select(brand);
        wait.until(new SelectCondition(selectBrand));           
        marcaSelect.selectByIndex(2);


        WebElement model= wait.until(ExpectedConditions.elementToBeClickable(By.id("model")));
        Select modelSelect = new Select(model);
        wait.until(new SelectCondition(modelSelect));
        modeloSelect.selectByIndex(2);

My custom expected conditions

class SelectCondition implements ExpectedCondition{

        Select select ;

        public SelectCondition(Select select){
            this.select = select;
        }

        public Boolean apply(Object arg0) {
            return  this.select.getOptions().size() > 1 ;
        }

    }

Im testing with selenium webdriver 3.3.1 , jsf 2.2 , java 1.7 , chrome , eclipse

Aucun commentaire:

Enregistrer un commentaire