FluentWait is WebDriverWait with more knobs to turn. You can set the polling interval (how often it retries), which exceptions to ignore, and a custom error message. WebDriverWait actually extends FluentWait under the hood.
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
Wait<WebDriver> fluentWait = new FluentWait<>(driver)
.withTimeout(Duration.ofSeconds(30)) // Max wait
.pollingEvery(Duration.ofMillis(250)) // Check every 250ms
.ignoring(NoSuchElementException.class) // Ignore during polling
.ignoring(StaleElementReferenceException.class) // Also ignore stale
.withMessage("Timed out waiting for balance to load");
WebElement balance = fluentWait.until(d ->
d.findElement(By.id("account-balance"))
);
System.out.println("Balance: " + balance.getText());For 95% of cases, WebDriverWait is enough. Use FluentWait when you need the extra control.
Q: What is FluentWait and how is it different from WebDriverWait?
A: FluentWait lets you configure the polling interval and which exceptions to ignore during polling. WebDriverWait is actually a subclass of FluentWait with defaults: 500ms polling and ignores NotFoundException. I use FluentWait when I need custom polling intervals (100ms for fast-changing elements), need to ignore StaleElementReferenceException, or want custom timeout messages for easier debugging.
Key Point: FluentWait = WebDriverWait with custom polling, custom ignored exceptions, and custom error messages. Use for advanced scenarios.