我正在用4個選擇測試一個表單。當我選擇第一個時,它會根據值進行ajax調用並填充下一個選擇。但大部分時間我都會遇到StaleElementReferenceException。 I'm實施FluentWait和我的自定義預期的測試狀態的選擇是使用相同的FluentWaitajax選項上的Selenium StaleElementReferenceException選項
FluentWait<WebDriver> wait = new FluentWait<WebDriver>(webdriver).withTimeout(10, TimeUnit.SECONDS)
.pollingEvery(2, TimeUnit.MILLISECONDS)
.ignoring(StaleElementReferenceException.class)
.ignoring(NoSuchElementException.class);
下面是檢索webelement代碼填充
I'm,並選擇第三個元素。
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);
我的定製預期條件
class SelectCondition implements ExpectedCondition{
Select select ;
public SelectCondition(Select select){
this.select = select;
}
public Boolean apply(Object arg0) {
return this.select.getOptions().size() > 1 ;
}
}
硒林webdriver的測試3.3.1,JSF 2.2,JAVA 1.7,鉻,日食
哪個特定的線路給你StaleEelementException? – kushal
return this.select.getOptions()。size()> 1; – jckhan