Selenium + Python · Lesson 21 of 43

0/43 done

Module 21: Dropdowns

21. Automating Dropdowns with the Select Support Class

15 minlesson

Your 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).

Write it in the editor, then press Check answer (Ctrl + Enter).

Using the Select Class

python
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)

Key Takeaways & Walkthrough Summary

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.

Common Doubts & Lesson Q&A

Can Select be used on modern custom div/span dropdowns?

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.

Python
Skip