Selenium + Python · Lesson 24 of 43
Module 24: Waits
Your task
Implement wait_for_clickable(driver, locator, timeout=10):
Write it in the editor, then press Check answer (Ctrl + Enter).
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
wait = WebDriverWait(driver, timeout=10)
# Wait until element is visible:
banner = wait.until(EC.visibility_of_element_located((By.ID, "welcome-banner")))
# Wait until clickable:
submit_btn = wait.until(EC.element_to_be_clickable((By.ID, "submit-btn")))
submit_btn.click()Welcome to Phase 4! Avoiding time.sleep() and mastering WebDriverWait is the key to eliminating flakiness in Python automation. In this lesson, you will master WebDriverWait combined with expected_conditions for visibility, clickability, and presence. Let's master waits!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
time.sleep() freezes the Python process unconditionally, slowing test suites when elements are ready early and failing when network delays exceed the hardcoded sleep.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___