- 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
What are the various 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”);
- Related Articles
- What are the various waits available in Selenium with python?
- What are the methods available for handling static dropdowns in a page in Selenium with python?
- What are different Navigator methods available?
- What are the various important exceptions in Selenium?
- What are the various Components of Selenium?
- What are various Inheritance mapping strategies available in Hibernate?
- How will you select a particular value in a dropdown without using the methods of Select class in Selenium?
- What are the various extraction methods in data warehouses?
- What are the various JSON files available in C# ASP.NET Core?
- What are the various locators that Selenium supports?
- What are the different cookies methods in Selenium?
- What are the different types of wait available in Selenium?
- What are the Actions class in Selenium?
- What are the differences between class methods and class members in C#?
- Name the various annotations available in TestNG.
