A guide on choosing an option from a dropdown list with Selenium

Struggling with choosing options from a list drop down box in Selenium.

Here's a snippet of the list box HTML and the Dropbox box:

<li class="MuiButtonBase-root MuiListItem-root MuiMenuItem-root Mui-selected MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button Mui-selected"
tabindex="0" role="option" aria-disabled="false" aria-selected="true" data-value="588ad39c8557bd23e3c16059">
(public) ISO<span class="MuiTouchRipple-root"></span></li>

<li class="MuiButtonBase-root MuiListItem-root MuiMenuItem-root MuiMenuItem-gutters MuiListItem-gutters MuiListItem-button" tabindex="-1"
 role="option" aria-disabled="false" data-value="611e693ad6018009c8f7c681">
(public) public.dwg<span class="MuiTouchRipple-root"></span></li>

Attempts using the select element have failed as the select class is not present in my code base.

Is there an alternative method to select items from the Dropbox without relying on a select class?

Your assistance would be highly appreciated. Looking forward to any helpful responses.

Note: Tried multiple solutions found online, but none were successful in solving the issue.

https://i.stack.imgur.com/S2Zsc.png

Answer №1

The Selenium Select class is specifically designed for dropdowns created using the Select and Option tags. However, in the HTML code you provided, a li tag is being used, which means that the Select method will not work.

Solution :

  1. Click on the dropdown menu.
  2. Select the desired option from the list.

Sample Code :

If you are working with Python, you can use the following approach :

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "XPath of the dropdown menu"))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//li[contains(text(),'(public) public.dwg')]"))).click()

Imports :

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

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

When attempting to generate a chrome instance using a different profile, new instances are created by chrome that are not linked to selenium

I am facing issues connecting to Chrome with the selected profile via options. Below is the code snippet: options.add_argument('--user-data-dir={}'.format(user_data_dir)) options.add_argument('--profile-dir={}'.format(profile_dir)) Eve ...

What are the best practices for managing certificates with Selenium?

I am currently utilizing Selenium to initiate a browser. What is the best approach for handling webpages (URLs) that prompt the browser to accept or deny a certificate? In the case of Firefox, I sometimes encounter websites that require me to accept their ...

Python Selenium Webdriver - Interacting with a button using a dynamic selector

I'm currently working on an automation project and facing a challenge with clicking this button using a selector. <button id="ember2570" class="ember-view btn btn-default btn btn-default" type="button"> <i class="fa fa-upload"></i&g ...

"Use the power of drag and drop with Selenium to navigate and interact with images inside

One of the requirements for my automated tests is to drag and drop an icon onto an image without a specific point B. While I know it's possible to drag and drop from point A to point B, this scenario presents a challenge. The HTML code for the image ...

Using Selenium and Python to scrape text from a continuously refreshing webpage after each scroll

Currently, I am utilizing Selenium/python to automatically scroll down a social media platform and extract posts. At the moment, I am gathering all the text in one go after scrolling a set number of times (see code below), but my objective is to only gathe ...

Is it possible to scroll upwards and then click using Selenium with Python?

I am facing an issue where I need to click on a button using selenium in python. Below is the code snippet I have been using: read_more_buttons = responses[0].find_elements_by_class_name("read-more") if len(read_more_buttons) > 0: ...

Encountering an unidentified issuer error code (SEC_ERROR_UNKNOWN_ISSUER) while using Python Webdriver with Firefox profiles

I've searched all over the internet but am still struggling to fix the error I encountered while attempting to run a test script on my testing environment. "The certificate is not trusted because the issuer certificate is unknown. The server migh ...

A guide to extracting information from a dynamic webpage using Selenium

As a beginner in the world of selenium, I am looking to extract the price and offer end time from a Udemy Course link. How can I achieve this? The price and course end time are dynamically loaded onto the website. While I have experience extracting simple ...

When attempting to automate tasks with selenium, I encountered a problem where the mouseover function was not functioning

Currently, I am working on automating a website and facing an issue while trying to access a specific submenu item by hovering over a menu. After extensive research, I found that using mouseover would be the best approach since the submenu only appears w ...

A Simple Java Method to Locate Elements

I am curious about how to convert these 2 generic methods for Selenium in C# into a Java version, as I do not have any experience with Java: public static IWebElement ConvertMethodForJava(Func<IWebDriver, IWebElement> expectedCondtions, int timeou ...

The WebDriver Manager for Selenium Automation is experiencing issues with the latest Chrome update, version 116

I implemented the selenium framework and included this dependency. However, I encountered an issue where the browser wasn't being invoked due to Chrome version 116. <dependency> <groupId>io.github.bonigarcia</groupId> <art ...

Using Selenium with Java to show suite results organized by run rather than individual test cases

In my quest to create a comprehensive TestNG report from a suite of test cases, I've encountered an issue. When a test case fails on the first or second run, it is permitted to run up to three times. However, my generated report only displays the resu ...

Obtain all the selection choices in a dropdown list using Selenium

Although I have come across similar questions, this one is distinct in its simplicity. Unlike other queries that involve iterating over options in a loop, my question revolves around the usage of the getOptions() method mentioned in Selenium documentation. ...

Expected "@" but got a syntax error on token "boolean"

I encountered an issue while trying to verify the presence of an alert message. I attempted to use the following code snippet: public boolean IsAlertPresent() { try { driver.switchTo().alert(); return true; ...

Issue with Selenium WebDriver in Opera browser: Not able to retrieve message from renderer

I'm currently facing an issue while attempting to run my Java Selenium tests using Opera browser (version 31). I have the latest versions of Selenium Webdriver (2.47.1) and OperaChromiumDriver (0.2.2) installed. I've experimented with two diffe ...

Retrieve a button using its name attribute in Selenium with Python

https://i.stack.imgur.com/MbJgQ.png In the HTML code below, there is a button that changes its x-path dynamically while the text "Show Actions" remains constant. I am uncertain whether "Show Actions" is the name, title, or id of the button. Is there a wa ...

What is the best way to have Selenium wait for an element to appear on the page?

Is there a way to make Selenium wait for an element that is added dynamically to the DOM after the page has loaded? I attempted this approach: fluentWait.until(ExpectedConditions.presenceOfElement(By.id("elementId"))); In case it's relevant, here is ...

The combination of spring, cucumber, and Selenium's fluent wait is causing my driver

I am attempting to implement fluent wait in my code @Component @Scope(SCOPE_CUCUMBER_GLUE) public class UserCreationPageImpl extends BaseBinariosPage implements UserCreationPage { Wait<WebDriver> wait = new FluentWait<WebDriver>( driver ) ...

What is the best method to find an element in a new webpage using XPath after navigating from the old page in Selenium?

Struggling to automate the login process on Flipkart and add a product to the cart. Whenever I click on the product, it redirects me to a new page where I can't find the specified element (add to cart button). Any assistance would be greatly appreciat ...

python utilizing selenium for scraping data from multiple href links

Click this link to test it out: I've been able to extract the links for all product detail pages, but I'm only getting one result at the end. It should be going through all the links and extracting the names and image URLs. What am I missing her ...