- 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 options in a drop-down list by Selenium WebDriver using C#?
We can get all options in a drop−down list by Selenium Webdriver in C#. The static drop−down in an html code is identified with a select tag. All the options for a drop−down have the option tag.
To obtain all the options in the form of a list, we shall first identify that element with the help of any of the locators like id, xpath, name, and so on. Then we must create an object of the SelectElement class and apply Options method on it.
Let us investigate the html code of drop−down.
For implementation we shall be using the NUnit framework.
Example
using NUnit.Framework; using OpenQA.Selenium; using OpenQA.Selenium.Firefox; using OpenQA.Selenium.Support.UI; using System; using System.Collections.Generic; using System.Linq; namespace NUnitTestProject1{ public class Tests{ String u = "https://www.tutorialspoint.com/selenium/selenium_automation_practice.htm"; IWebDriver d; [SetUp] public void Setup(){ //creating object of FirefoxDriver d = new FirefoxDriver(); } [Test] public void Test1(){ //launching URL d.Navigate() .GoToUrl(u); //identify dropdown IWebElement l = d.FindElement(By.Name("continents")); //object of SelectElement SelectElement s = new SelectElement(l); //Options method to get all options IList<IWebElement> els = s.Options; //count options int e = els.Count; for (int j = 0; j < e; j++){ Console.WriteLine("Option at " + j + " is: " + els.ElementAt(j).Text); } } [TearDown] public void close_Browser(){ d.Quit(); } } }
Output
Click on Run All Tests −
Click on Open additional output for this result link −
We should get the Test Outcome and Standard Output.
- Related Articles
- How to get all options of a dropdown using Python Selenium webdriver?
- How to display all items in the list in the drop down in Selenium?
- How to select/get drop down option in Selenium 2?
- How to automate drag & drop functionality using Selenium WebDriver Java?
- How to get selected text from a drop-down list (select box) using jQuery?
- How to select value from a drop down using Selenium IDE?
- How to scroll down using Selenium WebDriver with Java?
- How to get typed text from a textbox by using Selenium Webdriver?
- How to get all the options in the dropdown in Selenium?
- How to simulate HTML5 Drag and Drop in Selenium Webdriver?
- How to get HTTP Response Code using Selenium WebDriver?
- How to Scroll Down or UP a Page in Selenium Webdriver?
- How to scroll the Page up or down in Selenium WebDriver using java?
- How to list down all the cookies by name using JavaScript?
- How to add color to a drop-down list in Excel?

Advertisements