, , 'combo', , ExpectedCondtions.
Wait<WebDriver> newwait=new FluentWait<WebDriver>(driver).withTimeout(10, TimeUnit.SECONDS).pollingEvery(1, TimeUnit.SECONDS).ignoring(StaleElementReferenceException.class);
WebElement combo=newwait.until(new ExpectedCondition<WebElement>(){
@Override
public WebElement apply(WebDriver driver) {
WebElement found = driver.findElement(By.xpath(sXpath));
if (ExpectedConditions.stalenessOf(found).apply(driver)) {
return null;
}
return found;
}
});
2.47.2, FluentWait, , , null -, , , StaleElementException.
public <V> V until(Function<? super T, V> isTrue) {
long end = clock.laterBy(timeout.in(MILLISECONDS));
Throwable lastException = null;
while (true) {
try {
V value = isTrue.apply(input);
if (value != null && Boolean.class.equals(value.getClass())) {
if (Boolean.TRUE.equals(value)) {
return value;
}
} else if (value != null) {
return value;
}
} catch (Throwable e) {
lastException = propagateIfNotIngored(e);
}
if (!clock.isNowBefore(end)) {
String toAppend = message == null ?
" waiting for " + isTrue.toString() : ": " + message;
String timeoutMessage = String.format("Timed out after %d seconds%s",
timeout.in(SECONDS), toAppend);
throw timeoutException(timeoutMessage, lastException);
}
try {
sleeper.sleep(interval);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
throw new WebDriverException(e);
}
}
- , , , , , WebDriver . , , ...
<=
- dom
- (10 ), dom ( 30 )
- 10 . DOM
>
- dom
- (30 ), dom ( 10 )
- 10 , dom
- , SUCCEEDS
- .
. Implicit wait , -, , .
private final WebElement explicitWait(int retries, Predicate<Boolean> test) {
WebDriverWait wait = new WebDriverWait(driver, retries * getImplicitWait());
return wait.until(test);
}
Vinoth Thread.sleep, , . , .
.