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
5,187 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
8,263 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,476 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
14,348 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,360 points
545 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
13,491 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
9,030 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
7,145 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,816 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
684 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,492 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