Course → 1 · Selenium automation → Assertions & Structure
1 · Selenium automation
Assertions that catch regressions
10 min · Module 10
Automation is only useful when it fails for the right reasons. Assert titles, texts, counts, and URLs.
Example / notes
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
driver.get("http://127.0.0.1:8000/lab/table/")
assert "Team Directory" in driver.find_element(By.ID, "table-heading").text
rows = driver.find_elements(By.CSS_SELECTOR, "[data-testid='employee-row']")
assert len(rows) == 5
statuses = [r.find_element(By.CSS_SELECTOR, "[data-testid='cell-status']").text for r in rows]
assert "Active" in statuses
driver.quit()
Practice in Lab: /lab/table/
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