21. Automating Dropdowns with the Select Support Class

Using the Select Class

from selenium.webdriver.support.ui import Select

dropdown_elem = driver.find_element(By.ID, "country-select")
select = Select(dropdown_elem)

select.select_by_visible_text("United States")
select.select_by_value("US")
select.select_by_index(1)

Task

  • Implement select_option_by_text(element, text_to_select):
  • 1. Wrap element with Select(element).
  • 2. Call select.select_by_visible_text(text_to_select).
πŸ’‘Common doubts
Did you like the problem?
Lesson 21 of 43
Python
Loading code editor…
Next