Selenium has a neat way to handle drown down menus by using the Select function.
For this example, we will testing it out on:
https://app.endtest.io/guides/docs/how-to-test-dropdowns/
First let’s import the Select function.
from selenium.webdriver.support.select import Select
Now let's call the drop down by using its ID, which is pets and name its instance drop_down.
drop_down = driver.find_element_by_id('pets')
Now we've got the drop down selected and will name its instance drop.
drop = Select(drop_down)
There are multiple ways we can select values in a drop down menu, either by index, value or visible text.
drop.select_by_index(2)
drop.select_by_value('cat')
drop.select_by_visible_text("Dog")
The above is the detailed content of Easiest Way to Handle Drop Down Menus in Python Using Selenium ?. For more information, please follow other related articles on the PHP Chinese website!