In Selenium's Python bindings, what is the difference between an implicit wait and an explicit wait, and why is mixing the two discouraged?
Answer
An implicit wait (`driver.implicitly_wait(10)`) applies a single global timeout to every `find_element` call for the rest of the driver's lifetime, silently polling for up to that long whenever an element is not immediately present. An explicit wait (`WebDriverWait(driver, 10).until(condition)`) waits for a specific, named condition — element visible, clickable, text present — at one particular point in the test, giving far more precise and readable intent than a blanket timeout. Selenium's own documentation explicitly warns against mixing implicit and explicit waits in the same test, because their timeouts can interact unpredictably and produce inconsistent, hard-to-debug wait times.
Strong answer includes
- implicit wait sets one global timeout applied to every find_element call
- explicit wait targets a specific named condition at one point in the test
- mixing both is discouraged because their timeouts interact unpredictably
Practical example
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
login = WebDriverWait(driver, 10).until(
EC.element_to_be_clickable((By.CSS_SELECTOR, "[data-testid='login']"))
)
login.click()The explicit wait states exactly what must become true at this point in the test. This is more local and diagnosable than applying one implicit timeout to every element lookup.
Expected result: The click occurs only after the login element is present and clickable, or TimeoutException is raised after 10 seconds.