Course → 1 · Selenium automation → Waits
1 · Selenium automation
Explicit waits with WebDriverWait
14 min · Module 9
Dynamic pages need waits. Prefer WebDriverWait + expected conditions over time.sleep().
On the dynamic lab, click Load data and wait until #result is visible (about 2 seconds).
Example / notes
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()
driver.get("http://127.0.0.1:8000/lab/dynamic/")
driver.find_element(By.ID, "load-data").click()
result = WebDriverWait(driver, 5).until(
EC.visibility_of_element_located((By.ID, "result"))
)
print(result.text)
driver.quit()
Practice in Lab: /lab/dynamic/
Modules in this track
- 6. Getting Started
- 7. Finding Elements
- 8. Interactions
- 9. Waits
- 10. Assertions & Structure
- 11. Page Object Model
- 12. Alerts, Frames & Windows
- 13. Headless & Next Steps