Hello Folks,

Most of us we know that to handle a dropdown developed using Select tag, we can use inbuilt class of Selenium named “Select” class. This class provides you three methods to select options in dropdown which are below:

selectByValue – You need to provide exact value to get it selected.
selectByVisibleText – You need to provide exact text to get it selected.
selectByIndex – You must need to know index of desired of desired value.

If you want to select any value which contains some specific text, it will not be easy with above methods. I see people create their own special methods to handle this scenarios. But instead of using other ways, we can modify inbuilt functionality of class “Select” itself and use it for our specific scenarios.  So, in this post, I will explain how can we create a new method to select a option containing specific text.

Let’s create a select tag drop down as below:

Scenario : Select option which contains “Testing” in drop down.

We know it is not possible using inbuilt methods selectByVisibleText and selectByValue of Select class and selectByIndex will work only if you know the index in advance. Index is not a good option as it will change if new option is added in drop down.

So we will create a new custom method for Select class. I will use concept implemented in actual Select class with modification as required.

Scenario java code:


We will see some more custom methods in upcoming posts.

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



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

3 thoughts on “Advanced Selenium Concepts – Custom Select Class – Select Value Containing Specific Text in Drop down

  1. how to wait for ASP page to postback after selecting a dropdown list.

    I want to select a dependent dropdownlist in asp website which gives pincode of city after selecting State-District-City as dependent dropdown.
    please help me on this.

    please mail to my email if you got answer.
    i’m waiting…

Leave a Reply