SeleniumLab

Course1 · Selenium automation → Interactions

1 · Selenium automation

Selects and checkboxes

12 min · Module 8

For <select> elements, use Selenium’s Select helper. Checkboxes are toggled with click() when not already selected.

Example / notes

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

driver = webdriver.Chrome()
driver.get("http://127.0.0.1:8000/lab/form/")

driver.find_element(By.ID, "full_name").send_keys("Ada Lovelace")
driver.find_element(By.ID, "email").send_keys("ada@example.com")
Select(driver.find_element(By.ID, "role")).select_by_value("qa")
box = driver.find_element(By.ID, "newsletter")
if not box.is_selected():
    box.click()
driver.find_element(By.ID, "notes").send_keys("Automating forms")
driver.find_element(By.ID, "submit-form").click()

assert driver.find_element(By.ID, "form-success").is_displayed()
driver.quit()

Practice in Lab: /lab/form/

Log in to track progress / take quizzes
← Typing and clicking
Modules in this track