In this blog we will learn about dropdown handling in different ways in selenium without select class. In a website dropdown can be created in many different ways. Some dropdowns are created using <Select> HTML tag and some other dropdowns are created using <div>, <ul>, <li> and <button> HTML tags.
Selenium WebDriver allows select class which is used only for dropdown generating using <select> HTML tag. Select class has methods like selectByIndex(), selectByValue() and selectByVisibleText() to select the required option from dropdown.
No matter what, for Non Select dropdowns, Select class cannot be used. There must be a familiar way to handle different types of dropdowns in Selenium webDriver.
Let us examine different ways to handle Dropdown in Selenium without using Select tag.
Using Action Class
Using Send Keys
Using JavaScript Executor class
Creating custom Locator
Method 1: By using Action Class
In Selenium Action class is used for handling keyboard and mouse events.
Example: Launch the application and click on desired option
Action class in selenium can be used by importing import org.openqa.selenium.interactions.Actions package.
Method 2: By using SendKeys
For the above used application we can use sendkeys() method to select an option from dropdown by passing the elements value in send keys as shown in below example
Example:
Method 3: By using JavaScript Executor class
In Selenium WebDriver JavaScript is executed with the help of an interface called JavaScript Executor.
Example:
JavaScript Executor in selenium can be used by importing import org.openqa.selenium.JavascriptExecutor package.
Method 4: By creating custom Locator
We have to create custom locator and then handle the dropdown
Example:
I hope this blog helped you to learn handling Selenium Dropdowns without Select class. Thanks for reading!!!
Comments