How to handle Bootstrap dropdown in Selenium Webdriver

0 votes
How to handle Bootstrap dropdown in Selenium Webdriver?
Jul 19, 2019 in Selenium by Neeru
4,888 views

1 answer to this question.

0 votes

Hi Neeru, Bootstrap dropdown isn't like traditional dropdowns as it doesn't use <select> tags, rather it uses <ul> and <li> tags to make a dropdown. So to handle bootstrap dropdown, you need to use findElements() method which will return all the options of the dropdown. Following code snippet shows how to handle a bootstrap dropdown:

import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class BootstrapDropdown {

   public static void main(String[] args) throws InterruptedException {
       
      FirefoxDriver driver = new FirefoxDriver();

      driver.get("https://www.edureka.co");

      driver.findElement(By.className("icon-Home-page-humburger-menu-01​")).click();

      Thread.sleep(2000);

      //Dropdown items are coming in <a> tag so below xpath will get all elements and findElements will return list of WebElements

      List<WebElement> list = driver.findElementsByXPath("//ul[@id='hiddencat']//li/a");

       for (WebElement element : list)
       {
          System.out.println("Values " + element.getAttribute("innerHTML"));

       }

   }

}
answered Jul 19, 2019 by Anvi
• 14,150 points

Related Questions In Selenium

+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
7,971 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 6, 2018 in Selenium by nsv999
• 5,500 points
10,239 views
+1 vote
1 answer

How to handle notifications in Python with Selenium (Chrome WebDriver)

Below will help you: You can disable the ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
13,760 views
0 votes
1 answer

How to handle dropdown in Selenium?

Handling dropdown menus in Selenium WebDriver can ...READ MORE

answered Nov 9, 2023 in Selenium by anonymous
• 3,320 points
277 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
12,756 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
8,624 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
6,699 views
0 votes
2 answers

How to use such xpath to find web elements

xpath are two types. 1) Absolute XPath:    /html/b ...READ MORE

answered Sep 3, 2020 in Selenium by Sri
• 3,190 points
7,561 views
0 votes
1 answer

How to handle multiple windows in Selenium Webdriver?

Hey Ritika, you can handle multiple windows ...READ MORE

answered May 24, 2019 in Selenium by Anvi
• 14,150 points
535 views
0 votes
1 answer

How to click on Image in Selenium Webdriver?

Hello Lalit, I guess you mean to ...READ MORE

answered May 9, 2019 in Selenium by Anvi
• 14,150 points
12,099 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP