Make Selenium Easy

Handling Non-Select or Any Types Of dropdown In Selenium Webdriver

Last updated on May 25th, 2020 at 02:15 am

Selenium WebDriver provides a special class called Select which can be used only for drop down created using Select tag. You can not use this class methods for a Non-Select drop downs. This is a major limitation of Select class.

Drop downs in a website could be created in multiple ways. You will find maximum drop downs are created using ul and li tags. There are many drag and drop front end development tools which generates drop down codes dynamically. Sometimes you need to mouse hover on an element to see drop down options. In short, there should be a common way to handle any or most of drop down.

In this post, I will explain some common ways to handle any type of drop downs.

Click on drop down and iterate through options

This is a very common logic I see around. Steps are simple as below:-

  1. Click on drop down to make options visible.
  2. Get all options of drop down.
  3. Iterate through it and match with option to be selected.
  4. If found then click on option for selection.

Code snippet

You can write same logic using Sream API as below :-

Problem in above logic is that it is not optimal as it need to iterate over options. If your desired option to be selected in the list is at bottom position then whole options will be iterated and that will be a performance impact.

Optimal logic to select value in drop down without iteration

  1. Click on drop down to make options visible.
  2. Create a custom locator using option to be selected.
  3. Locate it and select.

Code Snippet

You can download/clone above sample project from here.

If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
#ThanksForReading
#HappyLearning

Find all Selenium related post here, all API manual and automation related posts here and find frequently asked Java Programs here.

Many other topics you can navigate through menu.

Author: Amod Mahajan

My name is Amod Mahajan and I am an IT employee with 6+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went through so many selenium tutorials. Thanks to Mukesh Otwani as his tutorials are easy and cover basics to advance. I have habit of exploring concepts by deep diving. I used to make notes. I thought of sharing my knowledge through posts and now I am here. #KeepLearning #ShareLearning

1 thought on “Handling Non-Select or Any Types Of dropdown In Selenium Webdriver

Leave a Reply

Please wait...

Subscribe to new posts to become automation expert

Want to be notified when my new post is published? Get my posts in your inbox.

Handling Non-Select or Any Types Of dropdown In Selenium Webdriver

by Amod Mahajan time to read: 3 min
1
%d bloggers like this: