Selenium + Python · Lesson 21 of 43
Module 21: Dropdowns
Your task
Implement select_option_by_text(element, text_to_select):
Write it in the editor, then press Check answer (Ctrl + Enter).
Select Classfrom 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)Standard HTML select tags require specialized handling. In this lesson, you will master Selenium's Select class to select by visible text, value, and index, and retrieve selected choices. Let's master dropdowns!
Part of the Selenium + Python course (Selenium with Python). Practice this concept live in the Selenium Online Compiler or explore our free automation practice form.
No! Select works exclusively on HTML <select> elements. For custom UI dropdowns, click the container to expand and click the option.
Ready? Solve the task in the editor
Use Check answer to mark it complete. Hints are there if you need them.
___