How to get all options of a dropdown using Python Selenium webdriver?

We can obtain all options of a dropdown with Selenium webdriver inPython using the method options. It returns a list of the options in the dropdown.

Then we have to use the method text, to get the option text.

A dropdown is represented by select tag and its available options are represented by the tagname option. To handle dropdown in Selenium, we have to take the help of the Select class.

Let us see the html code of a dropdown along with its options – By Subject and By Name.


l = driver.find_element_by_name("selType")
d = Select(l)

for opt in d.options -

m = opt.text


from selenium import webdriver
#set chromodriver.exe path
driver = webdriver.Chrome(executable_path="C:\chromedriver.exe")
#launch URL
#Select class for dropdown
l= driver.find_element_by_name("selType")
d= Select(l)
print('Options are: ')
#iterate over dropdown options
for opt in d.options:
#get option text
#browser quit