Dropdowns
~10 mins
Handling Dropdown:
What is a drop down?
- WebElement which allows the users to select one or more options from a list of predefined values.
How to handle dropdown?
- Using Select class in Selenium WebDriver
When to use?
- Element in the DOM is identified with
<select>
How to handle Dropdown?
- Dropdown elements are designed to select an option under a particular
category. - To handle dropdown , Selenium provides special class called Select class.
How to use Select class?
- Identify the element and confirm with
<select> - Instantiate the Select class by passing the WebElement as argument to the constructor.
Syntax:
- Select Class provides different methods to select the options from the dropdown.
Select options =new Select (webElement);
Note: (Select class should be imported from selenium.support.ui.Select)
Method 1
- uses index as input argument to select the option and the index starts from 0
selectByIndex(index) ;
Method 2
- uses the text (black colour) from DOM of that particular option
selectByVisibleText("text");
Method 3
- uses value of the value attribute as input argument to the method
selectByValue("value");