Browser Automation with Python and Selenium — 13: Working with Select Elements
How to interact with select elements
In the previous post, we looked at how to manage different kinds of alert dialogs. This post will be about working with select
elements on a web page.
The <select>
tag is used to create a drop-down list of options. It is usually used in a form to collect user input.
Selenium provides a Select class in the support package to manage select elements easily.
In order to start, we need to create a Select
instance with a select element. If you don’t give an element with the select
tag, UnexpectedTagNameException
is raised.
from selenium.webdriver.support.select import Select# ...element = driver.find_element(By.ID, "element_id")
select_object = Select(element)
If you created the Select
object successfully, you can start interacting with the options.
How to select an option?
There are 3 methods provided to select an option: