
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Methods Available Under Select Class in Selenium
The various methods available under Select class in Selenium are 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”);
-
getOptions()
This method fetches all the options under the select tag in form of list of web elements. It has no arguments.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.getOptions();
-
deSelectAll()
This method is used for multi select dropdown and removes all the options selected.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp >>"))); s.deSelectAll();
-
deselectByVisibleText(String args)
This method is used to deselect all options from a dropdown on basis of the text displayed that is similar to the argument. It takes a String parameter as argument and returns no values. This method is used for multi select dropdown.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByVisibleText("Selenium");
-
deselectByIndex(String args)
This method takes the index to deselect option in the dropdown. It takes an int parameter as argument and returns no values. This method is used for multi select dropdown.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByIndex(1);
-
deselectByValue(String args)
This method takes the value to select options in the dropdown. It takes a String parameter as argument and returns no values. This method is used for multi select dropdown.
Syntax −
Select s = new Select(driver.findElement(By.id("<< id exp>>"))); s.deselectByValue(“Testing”);