Skip to content

Wait Times - Implicit vs Explicit Waits

diagram implicit and explicit waits solve different problems mermaid
An implicit wait is a global setting that retries element lookups for up to N seconds. An explicit wait targets one condition and can wait for things that are not just presence -- clickable, visible, text changed. Mixing the two is the classic mistake, because the waits compound in ways that are hard to predict.

Dynamic pages load elements later.

If you try to locate elements too early, you get:

  • NoSuchElementException
  • ElementNotInteractableException
implicit_wait.py
from selenium import webdriver
 
 
driver = webdriver.Chrome()
driver.implicitly_wait(5)  # seconds

It applies to element lookups globally.

explicit_wait.py
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
 
 
driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
 
    h1 = WebDriverWait(driver, 10).until(
        EC.visibility_of_element_located((By.TAG_NAME, "h1"))
    )
    print(h1.text)
finally:
    driver.quit()

Prefer explicit waits for specific elements.

pch.coffeeTagline

pch.coffeeCta

pch.feedbackHeading

pch.feedbackSubheading