SeleniumLab

Course1 · 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/

Log in to track progress / take quizzes
← Locators: ID, CSS, and XPath
Modules in this track