Testing / Selenium Interview questions
How does Selenium's WebDriverWait work with ExpectedConditions?
WebDriverWait repeatedly polls a supplied condition, defined via the ExpectedConditions utility class, until it returns a truthy result or the configured timeout elapses.
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10)); WebElement btn = wait.until( ExpectedConditions.elementToBeClickable(By.id("submit")) ); btn.click();
ExpectedConditions provides prebuilt conditions like visibilityOfElementLocated, elementToBeClickable, textToBePresentInElement, and invisibilityOfElementLocated, each encapsulating the specific check and exception-swallowing logic needed so the wait loop doesn't crash on a transient NoSuchElementException mid-poll. Custom conditions can also be supplied as a lambda implementing Function<WebDriver, T> when no built-in condition fits.
By default, WebDriverWait re-throws whatever the underlying condition ultimately fails with, but it can also be configured to ignore specific additional exception types during polling via .ignoring(), which is useful when a condition might legitimately hit a transient error while the page is still settling.
More Related questions...