Never Mix Implicit and Explicit Waits

Why Mixing Is Bad

The Selenium documentation warns: do not use implicit and explicit waits together. Inside an explicit wait, every findElement also waits implicitly, so the total time becomes unpredictable.

SetupWaiting for an element that never appearsActual time before failure
explicit 10 s onlypolls every 500 msabout 10 s
implicit 10 s + explicit 15 seach poll itself waits 10 sabout 20 s (can vary)
implicit 10 s + invisibilityOf checkeach findElement waits for the element to existslow "is it gone?" checks

Team Rule

  • Set implicit wait to 0 (the default) and use explicit waits for everything.
  • Wrap common waits in helper methods so tests stay short.
public class Waits {
    private final WebDriverWait wait;
    public Waits(WebDriver driver) { this.wait = new WebDriverWait(driver, Duration.ofSeconds(10)); }

    public WebElement visible(By by)   { return wait.until(ExpectedConditions.visibilityOfElementLocated(by)); }
    public WebElement clickable(By by) { return wait.until(ExpectedConditions.elementToBeClickable(by)); }
    public void gone(By by)            { wait.until(ExpectedConditions.invisibilityOfElementLocated(by)); }
}

waits.clickable(By.id("add-to-cart")).click();
waits.gone(By.cssSelector(".spinner"));