Handle Bootstrap Dropdown In Selenium Webdriver

Boot strap dropdown

Handle Bootstrap Dropdown In Selenium Webdriver

In this tutorial will discuss on how to handle bootstrap dropdown in selenium webdriver.

Everyone is familiar with handling drop downs but when you work in real time you may or may not get the select class drop down. For example, there is boot strap drop down in this case we don’t have select class so obviously we don’t have methods like ‘selectByText()’, ‘selectByIndex()’ and ‘selectByValue()’.

To handle above problem, solution is first we need to grab all the elements present in drop down and loop through each element until you get your desired element and then you can click the element.

In selenium Webdriver it is one of the main functionality while dealing with web elements.

This is the best approach to handle bootstrap dropdown in selenium web driver also you can say that handle dropdown without select in selenium java.

In Below image you can able to see list of items if you want to select any specific element example if you want to select ‘Java’. You can iterate all the elements, when you found the element you can stop using break statement from java.

 

DropDown

Find the sample code below for handling dropdown without select in selenium, I have handled single element , suppose if you want to select multiple items, yes you can do but you need to give break statement once you reach final element.

From below program you can able to find

1)How to get the count all elements from the dropdown.

2)How to get the name of all elements from the dropdown.

3)How to iterate all the elements in the dropdown.

4)How to stop at specific element.

All above points will be useful in interview. All the best ?

Note: I have used chrome driver . if you want to download driver you can get from selenium official website or simply you can click here.

Please provide your comments or you need more info on this. Thank you ?.

You May Also Like

About the Author: Azgar Khan

14 Comments

  1. Yes..you are absolutely right…I was fallen this situation previously..thinking why select class dropdown could not find selectByText(), selectByIndex() and selectByValue() methods…I spent more than 3days to find out how to achieve but your stuff is very simple,consice and clean…great one..

Leave a Reply

Your email address will not be published. Required fields are marked *