Advanced Selenium Concepts – Custom Select Class – Select Value Containing Specific Text in Drop down

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:

  1. selectByValue – You need to provide exact value to get it selected.
  2. selectByVisibleText – You need to provide exact text to get it selected.
  3. 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 4+ years of experience in Software testing and staying in Bengaluru. My area of interest is Automation testing. I started from basics and went throw 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