- 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 select a value from a static dropdown in Selenium?
The various methods available under Select class in Selenium to select a
value from a static dropdown. They are as listed below −
selectByVisibleText(String args)
This method is most commonly used in dropdowns. It is very simple to select an option in a dropdown and multiple selection box with this method. It takes a String parameter as argument and returns no values.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByVisibleText("Selenium");
selectByIndex(String args)
This method takes the index of the option to select in the dropdown. It takes an int parameter as argument and returns no values.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByIndex(1);
selectByValue(String args)
This method takes the value of the option to select in the dropdown. It takes a String parameter as argument and returns no values.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.selectByValue(“Testing”);
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 SelectOptions{ 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’]"))); // select an option by value method s.selectByValue("name"); Thread.sleep(1000); // select an option by index method s.selectByIndex(0); Thread.sleep(1000); // select an option by visible text method s.selectByVisibleText("By Subject"); Thread.sleep(1000); driver.quit(); } }
- Related Articles
- How to select an option in a static dropdown in Selenium?
- How to Select Value from DropDown using Selenium Webdriver?
- How to verify if we can select multiple options in a static dropdown in Selenium?
- How will you select a particular value in a dropdown without using the methods of Select class in Selenium?
- How to select an item from a dropdown list using Selenium WebDriver with java?
- Gecko driver, Selecting value from a dropdown list using Selenium
- How to select value from a drop down using Selenium IDE?
- What are the different ways to select an option from a dropdown using Selenium Webdriver?
- How will you deselect an option from a static dropdown?
- Handling DropDown And Multiple Select in Webdriver using Selenium
- How to add static value while INSERT INTO with SELECT in a MySQL query?
- How to select multiple options in a dropdown list with JavaScript?
- How will you get all the options in a static dropdown?
- How to select a drop-down menu option value with Selenium (Python)?
- How to Select date from a datepicker with Selenium Webdriver using Python?

Advertisements