</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

Explain the difference between implicit wait and explicit wait in Selenium.

Implicit wait applies globally to all element lookups; explicit wait targets a specific element with a specific condition.

Answer

Implicit Wait — global wait applied to ALL findElement() calls:

Java
driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(180));
  • Set once, applies throughout the entire WebDriver session
  • Waits up to the specified time before throwing NoSuchElementException
  • Cannot wait for specific conditions (visibility, clickability, etc.)

Explicit Wait — applied to a SPECIFIC element with a SPECIFIC condition:

Java
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(5));
wait.until(ExpectedConditions.presenceOfElementLocated(ElementLocator));
  • Created per use — does NOT apply globally
  • Supports rich conditions: visibilityOf, elementToBeClickable, alertIsPresent, etc.
  • Exits as soon as the condition is met (no unnecessary waiting)

Key comparison:

Implicit WaitExplicit Wait
ScopeGlobal (all elements)Specific element only
Condition supportPresence onlyAny ExpectedCondition
Set upOnce per sessionPer usage
Best forSimple scriptsProduction frameworks

Best Practice: Never mix implicit and explicit waits — it causes unpredictable timing behavior. Choose one strategy per project and stick to it. Explicit wait is preferred for production frameworks.

Follow AutomateQA

Related Topics