9. Handling Dropdowns, Checkboxes and Radio Controls

Working with the Select Class

from selenium.webdriver.support.ui import Select

# Locate select tag:
country_dropdown = Select(driver.find_element(By.ID, "country-select"))

# Select by visible text:
country_dropdown.select_by_visible_text("Canada")

# Checkboxes:
checkbox = driver.find_element(By.ID, "agree-terms")
if not checkbox.is_selected():
checkbox.click()

Task

  • Implement should_toggle_checkbox:
  • 1. Accept is_selected (bool) and desired_state (bool).
  • 2. Return is_selected != desired_state.
💡Common doubts
Did you like the problem?
Lesson 9 of 16
Python
Loading code editor…
Next