Failure to select a menu item from a Bootstrap dropdown using Selenium

Automating a Bootstrap drop-down menu can be tricky, especially when the visibility is hidden by default. However, with Selenium, it's possible to make it visible and interact with it.
        

When trying to automate the bootstrap drop-down menu using Selenium, an issue arose where after clicking on the dropdown, the script was not selecting a value from it. The following exception was encountered:

Error: Exception in thread "main" org.openqa.selenium.ElementNotVisibleException: Cannot click on element

Here is a snippet of the HTML code for reference:

<a class="ui-button-text-icons" id="ctl00_Sitemap1_HyperLink1" href="javascript:void(void);">
    <span style="padding-right: 1.3em;">Dashboards</span>
    <span class="ui-button-icon-secondary ui-icon ui-icon-triangle-1-s"></span>
</a>
<ul style="visibility: hidden;">
    <li class="first featureGranted">
        <a href="ClassicDashboard.aspx">Classic Dashboard</a>
    </li>
</ul>

Answer №1

Here are a few key points to consider:

  • Instead of going through all li elements, use Xpath to locate the desired element.
  • Avoid using JavaScript to click on elements unless Selenium's click method is not working properly.
  • If you encounter an error stating that the element is not visible, try using Explicit Wait until the element becomes visible, as shown below.

Code Snippet

Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("//*[@id='ctl00_Sitemap1_HyperLink1']"));
action.moveToElement(we).build().perform();
WebElement tmpElement= driver.findElement(By.xpath("//*[@id='ctl00_Sitemap1_HyperLink1']"));
JavascriptExecutor js = (JavascriptExecutor) driver;
// It's recommended to avoid clicking with JavaScript unless necessary
js.executeScript("arguments[0].click();", tmpElement);

WebDriverWait wait = new WebDriverWait(driver, 30);
WebElement eventDashboardMenu = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[contains(text(),'Event Dashboard')]")));
eventDashboardMenu.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

Automating desktop applications using web technologies through Selenium WebDriver with NW.js and the Chromium Extended Framework

I am currently in the process of automating my standalone desktop application, which is built using web technologies and integrated with the Chromium Embedded Framework via NW.js. The application I am testing is a desktop-based implementation utilizing we ...

Set up Capybara to trust any SSL certificate presented

Could use some guidance on getting Capybara (1.1.1) to automatically accept SSL certificates while using Chrome. Here's my current Capybara setup: Capybara.run_server = false Capybara.app_host = 'http://some.host.com' Capybara.default_driv ...

Protractor: Decrease the magnification

Currently, I am working with protractor and facing the challenge of zooming out to 50%. Despite trying numerous solutions found on StackOverflow, none have successfully resolved the issue. Some attempted solutions include: browser.actions().keyDown(protra ...

Please transmit the username and password information using Selenium

I am trying to extract data from a website within my local network using selenium, and I need to provide the login credentials. The challenge is that there are no inspect elements available to locate the Username and Password fields on the webpage. You c ...

Attempting to interact with an interactive element manually, as it is not responsive to automated testing in C# code

I am facing a challenge in automating tests for a mobile application built with Flutter using Selenium and Appium in C#. Specifically, there is a section where I need to select the purchase date for an item. Despite my efforts, I have been unable to click ...

Encountering ERR_TUNNEL_CONNECTION_FAILED error with Seleniumwire.py while utilizing Proxies

After extensive research, I attempted to integrate authenticated proxies into my selenium code. However, when using Selenium Wire, I encountered the following error: selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_TUNNEL_CON ...

How can I trigger an Onclick event from an <a tag without text in a Javascript form using Selenium?

Here is my original source code: <a onclick="pd(event);" tabindex="0" issprite="true" data-ctl="Icon" style="overflow: hidden; background: transparent url("webwb/pygridicons_12892877635.png!!.png") no-repeat scroll 0px top; width: 16px; height: 16px ...

Python Selenium Webdriver for Authentication Popups

When using Selenium and win32com.client, I am able to send keys to handle the authentication popup of a site successfully when running the code manually in a Jupyter Notebook. The issue arises when I try to convert the .ipynb file to .py and schedule it t ...

Sauce Labs encountering issues when running JavaScript code

Currently, I am using Selenium WebdriverJs along with Mocha to conduct tests on Sauce Labs via Travis CI. After isolating the issue without any project dependencies, I am seeking help. The interesting observation is that defining an additional object with ...

Discovering the browser handle for a newly opened IE window in Selenium Java

Currently, I am focused on automation testing using Selenium with Java. In my current scenario, the first step involves opening the login page and then providing credentials before clicking the Login button. After this action is completed, the current brow ...

What is the reason Selenium is able to click on radio buttons using Chrome and Firefox, but encounters issues with IE 9?

I am currently using Python 3.4 in conjunction with Selenium Webdriver python bindings on my Windows machine. My script successfully tests my website when utilizing the Selenium Chrome and Firefox webdrivers. However, upon switching to the IE webdriver, it ...

Exploring the Power of Selenium and Python on Snow Leopard

Having recently switched to using the stock Python (2.6.1) on Snow Leopard with Selenium, I find myself encountering some issues. As a novice in the realm of Python, I am struggling to pinpoint where exactly I have gone wrong, especially since this same pr ...

Streamline your workflow with Selenium and Python to automate tasks on the Outlook Web App

I have been working on automating the process of sending emails using my office Outlook web app. I have managed to automate the login process successfully, but I am facing an issue with clicking on the new tab for composing and sending emails as there is n ...

Error message: Selenium/C# - Element is not visible

After successfully locating the button element using an Xpath, I encountered a element not visible exception when attempting to click on it. <div class="modal-footer"> <button id="btnRegister" type="button" class="btn btn-primary btn-block"> ...

having difficulty choosing an item from a dropdown menu using selenium webdriver

When working with dropdown menus in HTML, selecting an item can be a bit tricky since the html tag is not used as a select option for dropdowns. In this case, using Actions to interact with the dropdown menu may be necessary. Is it standard practice to us ...

How to use Selenium to interact with an array of string elements and perform clicks

I have a String array that I obtain from either a text file or CSV. My goal is to use Selenium to click on each checkbox element corresponding to the elements in the array. The checkboxes follow this naming convention: 1.0.50.gecb16, 1.1.50.gecb16, 1.2. ...

Tips for choosing and utilizing a Modal form with Java for data input

I am currently testing the login functionality on the website using Selenium WebDriver in conjunction with Java. The implementation follows the Page Object Factory design pattern. To initiate the login process, I navigate to the specified site, click on ...

What is the process for passing pre-determined functions as parameters of another function?

In my programming project, I have designed two classes. The first class, TextElement, is a selenium extension with various text properties where the Text method retrieves a string value from the element. The second class, ArrayTextElement, is essentially a ...

during the process of conducting data-driven testing with Selenium WebDriver

I'm encountering an issue while trying to perform data driven testing through Excel using Selenium WebDriver. I keep getting an error 'Exception in thread "main" java.lang.NullPointerException' and I am using POI jar files. Here is the code ...

Dealing with a webpage element that Selenium identifies as "NOT visible" when clicked on, on a login page: helpful tips

I have been working on automating the login process for a web application using Selenium WebDriver. I managed to locate the user and password input fields, entered the values using sendKeys(), but encountered an issue when trying to click on the submit but ...