Course → 1 · Selenium automation → Finding Elements
1 · Selenium automation
find_element vs find_elements
8 min · Module 7
find_element returns one match or raises NoSuchElementException.
find_elements returns a list (possibly empty) — ideal for tables and repeating rows.
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/")
rows = driver.find_elements(By.CSS_SELECTOR, "[data-testid='employee-row']")
print(f"Found {len(rows)} employees")
for row in rows:
name = row.find_element(By.CSS_SELECTOR, "[data-testid='cell-name']").text
print("-", name)
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