How to handle Bootstrap dropdown in Selenium Webdriver?

0 votes
How to handle Bootstrap dropdown in Selenium Webdriver?
Jul 18 in Selenium by Neeru
126 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 18 by Anvi
• 13,960 points

Related Questions In Selenium

0 votes
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,110 points
2,266 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 5, 2018 in Selenium by nsv999
• 5,110 points
4,938 views
0 votes
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,130 points
2,634 views
0 votes
3 answers

How to specify "ENTER" button functionality in Selenium WebDriver code?

using OpenQA.Selenium.Interactions; Actions builder = new Actions(driver); ...READ MORE

answered Feb 12 in Selenium by anonymous
11,253 views
0 votes
1 answer

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,110 points
916 views
0 votes
1 answer
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,130 points
1,102 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
838 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 in Selenium by Anvi
• 13,960 points
66 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 in Selenium by Anvi
• 13,960 points
972 views