- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Syntax
l = driver.find_element_by_name("selType") d = Select(l)
for opt in d.options -
m = opt.text
Example
from selenium import webdriver #set chromodriver.exe path driver = webdriver.Chrome(executable_path="C:\chromedriver.exe") driver.implicitly_wait(0.5) #launch URL driver.get("https://www.tutorialspoint.com/tutor_connect/index.php") #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 print(opt.text) #browser quit driver.quit()
Output
- Related Articles
- How to get all the options in the dropdown in Selenium?
- How to get all options in a drop-down list by Selenium WebDriver using C#?
- How to Select Value from DropDown using Selenium Webdriver?
- How will you get all the options in a static dropdown?
- How to get selected option using Selenium WebDriver with Python?
- Selenium WebDriver and DropDown Boxes.
- Handling DropDown And Multiple Select in Webdriver using Selenium
- How to select an item from a dropdown list using Selenium WebDriver with java?
- Get HTML Source of WebElement in Selenium WebDriver using Python.
- How to refresh a webpage using Python Selenium Webdriver?
- How to get HTTP Response Code using Selenium WebDriver?
- How to get selected option using Selenium WebDriver with Java?
- JavaScript get the length of select options(dropdown)?
- Take screenshot of the options in dropdown in selenium c#.
- How to show all the options from a dropdown list with JavaScript?

Advertisements