Navigating Through Nested Elements with Selenium Using CSS Selectors for BootStrap Styling

Hey everyone, I'm working on a web page that's structured in bootstrap and I need to access the elements of my dropdown menu. I've been using the Firefox Selenium IDE to obtain the XPath, which validates successfully showing that the path exists. However, when I try to click on the element, I encounter an error.

    org.openqa.selenium.NoSuchElementException: Unable to locate element:

Here is the code I'm working with, and I'm looking for assistance in being able to navigate to the dropdown menu and click on the available links:

<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse pull-left" id="navbar-collapse">
    <ul class="nav navbar-nav">
        <li class="dropdown">
            <a href="#" class="dropdown-toggle hidden-xs" data-toggle="dropdown"><i class="glyphicons glyphicons-bed-alt"></i> Management<span class="caret"></span></a>

            <ul class="dropdown-menu" role="menu">
                <li class="hidden-xs">
                    <a href="/Occupancy" onclick="clearStorage(); return true;"><span><i class="glyphicons glyphicons-bed-alt"></i> Occupancy</span></a>
                </li>
                <li class="hidden-xs">
                    <a href="/List"><span><i class="glyphicons glyphicons-bed-alt"></i> Ward Occupancy</span></a>
                </li>


            </ul>
        </li>


    </ul>

</div>

I am seeking guidance on how to locate the "Management" element and successfully click on the dropdown options. Thank you for your help!

Answer №1

I came across a helpful resource that finally provided me with the answer I was looking for regarding handling bootstrap dropdowns in Selenium WebDriver. The guide can be found at this link. When dealing with bootstrap drop-down menus, it's important to locate the element, click to open it, and then interact with the links within.

    driver.findElement(By.xpath("//a[contains(text(),'Management')]")).click();

    Thread.sleep(2000);

       driver.findElement(By.xpath("//div[@id='navbar-collapse']/ul/li/ul/li/a/span")).click();

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Having trouble with your Selenium WebDriver JUnit test?

I encountered an error in my script. Could this indicate a missing jar file that needs to be included in the library, or is it something else? ...

Unable to establish a connection with Geckodriver

Attempting to execute the Selenium example script with Ruby on Rails, I encountered an issue when trying to run it with a proxy. Below is the code snippet: require 'rubygems' require 'bundler/setup' # require your gems as usual requir ...

Executing the Page Object Model Strategy

I'm currently working on a test automation project utilizing Perl and Selenium with the Page Object Model. I'm grappling with where exactly the Selenium driver should be incorporated into this model. Is it necessary for every page object to poss ...

Closing Internet Explorer 9 browser session with popup using Selenium Ruby Webdriver

While making some changes to a page on my web application, a popup message appears saying "This page is asking you to confirm that you want to leave - data you have entered may not be saved" with options to "Leave Page" or "Stay on Page". If I am using FF ...

Is it possible to bypass detection using Python Selenium?

Attempting to extract data from this webpage - But facing detection as soon as the request is made, any workaround for this issue? Previously tried using Request but encountered detection. *Scrapy cannot be utilized in this particular project. Struggling ...

Discovering a specific URL link element within the DOM using webdriver.io

I am currently utilizing webdriver io for conducting tests on a webpage. I am in need of verifying the existence of an element with a specific href on the page. I have attempted to achieve this using the following snippet var client = webdriverio.remote ...

Retrieve the id of an element with a specified style value "x" using Java and Selenium

Whenever I load a page, I notice the presence of the following code: <div id="policySetup_content"> <div id="bCS_insureds_contentWrap" style="display: none;"> <div id="bCS_policy_contentWrap" style="display: block;"> <div ...

Seeking the perfect message to display upon clicking an object with Protractor

Currently, I am using Protractor 5.1.1 along with Chromedriver 2.27. My goal is to make the script wait until the message "Scheduling complete" appears after clicking on the schedule button. Despite trying various codes (including the commented out code), ...

I am in the process of automating an Android hybrid application with Appium, but I am encountering difficulty when trying to switch to the WEBVIEW

Here are the environment details: The application is built with Cordova Ionic Appium version is 1.4.16.1 Android version is 6 (Nougat) I'm stuck due to an issue with this setup. Can anyone provide assistance to help resolve this problem? P ...

How can you compare the values of two elements in Appium to confirm if they are equal?

After clicking on element1, it redirects me to a different page where I click on element2. When I return to element1, I expect the text to be updated to match that of element2. How can this be verified using Appium? I'm unsure how to verify this if e ...

Having difficulty in choosing and displaying the dropdown values

Below is the code snippet: WebElement pooldropdown=driver.findElement(By.xpath("/html/body/section/section[2]/div[1]/select")); Select sel = new Select(pooldropdown); List<WebElement> list = sel.getOptions(); System. ...

An exception has occurred in the OpenQA.Selenium.WebDriverException

Hi, I have been working on a C# Windows Form application that utilizes Selenium to open Edge browser. It was working fine before, but suddenly after months, I started encountering this error: An unhandled exception of type 'OpenQA.Selenium.WebDriverE ...

Ways to retrieve data from another tab using Selenium

From my understanding, Selenium currently opens a "private" browser tab. I am curious if there is a way to modify this behavior so that the Selenium tab can interact with other open tabs, allowing it to access logged-in sessions without needing to log in ...

Having trouble choosing options from the dropdown menu for Admin or ESS on the Orange HRM site for UserRole

As a newcomer to Selenium and Python, I am embarking on creating a pytest framework from scratch. The URL The credentials for login are provided on the test site login page (and below): Username: Admin Password: admin123 I am facing difficulty in cl ...

Executing selenium tests within a dockerized django environment

When it comes to running tests, my usual approach involves launching a separate container using the following command: docker-compose run --rm web /bin/bash The 'web' container contains django, and I typically run py.test from a shell periodica ...

How to interact with md-sidenav using Selenium

I am facing a challenge with my web-page that contains an md-sidenav as I attempt to test it using selenium. Everything else on the page seems to be functioning correctly, except when I try to interact with elements inside the md-sidenav. Despite confirmin ...

Looking to configure Selenium to continuously click a specified target until a specific element becomes visible?

I'm currently working on developing an automated checkout system for a website. My goal is to have it click the "add to cart" button repeatedly until the "checkout" button becomes visible. However, I am facing a challenge as the current setup only all ...

In Selenium, there seems to be an issue with IE11 not being able to locate an element using xpath, even though Chrome

HTML <tr> <td class="label" width="30%" valign="bottom">SOID: </td> <td class="desc" valign="top">123456789</td> </tr> I am interested in extracting the value "123456789" Xpath ".//td[contains(@class, ...

Utilizing Selenium: Implementing user input prompts and efficiently incorporating the input values

Currently, I am facing an issue during a selenium test where the user needs to enter a security code to proceed. However, retrieving the value of the input is proving to be a challenging task. After exploring the Selenium documentation, I attempted the fol ...

Java - Selenium: The challenge of working with nested <html> elements in Selenium testing

I'm currently conducting a test on a web page using Java and the Selenium API. The structure of the web page looks like this: <html> <head> </head> <frameset name="f1"> <html> <frameset ...