Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Posted on 04/23/2025 By admin

Hello Folks,

In last post we have seen an important topic in Selenium Webdriver which was Handling Any Types Of Listbox/dropdown In Selenium Webdriver. Method discussed in this post will work for all types of drop-down created using any tags.

Mostly drop-down are created using tag and Selenium provides a special way to handle such drop-downs. It is very simple and easy.

We will cover below topics in this post:

  1. What is SELECT tag?
  2. Types of SELECT drop-downs.
  3. How to create drop-downs.
  4. What is Select class?
  5. Why we get UnexpectedTagNameException while using Select class?

What is tag?

The element, used along with one or more elements, creates a drop-down list of options for a web form. The element creates the list and each element is displayed as an available option in the list.

Drop-down can be of two types:

1. Single select drop-down: You can select only single value at a time.
2. Multi select drop-down: You can select more than one value at a time.

Single select drop-down example:

If you open above html code in a browser, you will drop-down as below:

[xyz-ihs snippet=”SingleSelectDropdown”]

Click on drop-down, you will see list of values. Choose any one value, that value will be shown as selected.

Multi select drop-down example:

To create a multiple drop-down, just you need to use “multiple” word within SELECT tag as shown below:

If you open above html code in a browser, you will drop-down as below:

[xyz-ihs snippet=”MultiSelectDropdown”]

You can select multiple values from above drop-down using ctrl key.

Handling tag drop-down in Selenium:

  • Selenium developers provides a special class called “Select” to handle drop-down.
  • “Select” class is in “org.openqa.selenium.support.ui” package.
  • “Select” class models a SELECT tag and provides helper methods to select and deselect options.

Constructor in Select class:

I will explain a very common mistake done by Selenium beginners under this header.

As of now, we know “Select” class can be used only for SELECT tag drop-down. What happens when you try to use “Select” class for non SELECT tag drop-downs. Let’s see below example:

“Select” class provides an argument constructor which accepts a web element which should be a tag web element. This constructor checks that the given web element is a SELECT tag or not. If it is not, then an UnexpectedTagNameException is thrown.

Let’s see an example here:

If you see above code, drop-down is created using UL tag in stead of SELECT tag. We will locate drop-down first and then we will pass drop-down web element to Select class constructor.

Program:

Output:

Uncategorized

Post navigation

Previous Post: Why It Is Not Possible To Read Locators From External Sources In Page Factory Of Selenium WebDriver
Next Post: Features of Selenium 4.0.0 Release – Java Binding

Related Posts

January 25, 2019 – Make Selenium Easy Uncategorized
Manual Testing Uncategorized
August 24, 2018 – Make Selenium Easy Uncategorized
ExeInUse – Make Selenium Easy Uncategorized
TestNG Tutorials 40: Groups of Groups or MetaGroups in TestNG Uncategorized
Understand Severity And Priority Of A Defect In Software Testing Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark