selenium-webdriver Wait Fluent Wait

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

Example

Fluent wait is a superclass of explicit wait (WebDriverWait) that is more configurable since it can accept an argument to the wait function. I'll pass on implicit wait, since it's a best practice to avoid it.

Usage (Java):

Wait wait = new FluentWait<>(this.driver)
        .withTimeout(driverTimeoutSeconds, TimeUnit.SECONDS)
        .pollingEvery(500, TimeUnit.MILLISECONDS)
        .ignoring(StaleElementReferenceException.class)
        .ignoring(NoSuchElementException.class)
        .ignoring(ElementNotVisibleException.class);

WebElement foo = wait.until(ExpectedConditions.presenceOfElementLocated(By.yourBy));

// or use your own predicate:
WebElement foo = wait.until(new Function() {
  public WebElement apply(WebDriver driver) {
    return element.getText().length() > 0;
  }
});

When you use Explicit wait with it's defaults it's simply a FluentWait<WebDriver> with defaults of: DEFAULT_SLEEP_TIMEOUT = 500; and ignoring NotFoundException.



Got any selenium-webdriver Question?