- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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 the options in the dropdown in Selenium?
We can extract all the options in a dropdown in Selenium with the help of Select class which has the getOptions() method. This retrieves all the options on a Select tag and returns a list of web elements. This method does not accept any arguments.
Example
import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import org.openqa.selenium.chrome.ChromeDriver; import java.util.concurrent.TimeUnit; import java.util.List; import org.openqa.selenium.support.ui.Select; public class DropdownOptions{ public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "C:\Users\ghs6kor\Desktop\Java\chromedriver.exe"); WebDriver driver = new ChromeDriver(); String url = " https://www.tutorialspoint.com/tutor_connect/index.php"; driver.get(url); driver.manage().timeouts().implicitlyWait(12, TimeUnit.SECONDS); Select s = new Select(driver.findElement(By.xpath("//select[@name=’selType’]"))); // getting the list of options in the dropdown with getOptions() List <WebElement> op = s.getOptions(); int size = op.size(); for(int i =0; i<size ; i++){ String options = op.get(i).getText(); System.out.println(options); } driver.quit() } }
- Related Articles
- How to get all options of a dropdown using Python Selenium webdriver?
- How will you get all the options in a static dropdown?
- Take screenshot of the options in dropdown in selenium c#.
- How to get the number of options in the dropdown list with JavaScript?
- JavaScript get the length of select options(dropdown)?
- How to show all the options from a dropdown list with JavaScript?
- How to verify if we can select multiple options in a static dropdown in Selenium?
- How to get all options in a drop-down list by Selenium WebDriver using C#?
- Highlighting Dropdown Options in ReactJS
- How to select multiple options in a dropdown list with JavaScript?
- How to get all the values in a worksheet in Selenium with python?
- How to remove options from a dropdown list with JavaScript?
- How to select an option in a static dropdown in Selenium?
- How to select a value from a static dropdown in Selenium?
- How to Select Value from DropDown using Selenium Webdriver?

Advertisements