Is there a way for me to select an option from the dropdown list in this specific code?

Apologies for any confusion caused by the code I shared. My goal is to automate the dropdown feature, but I am only familiar with using the Select class and unsure of how to proceed. Please refer to the image linked below and provide guidance on selecting this particular dropdown:

=============================================================================[1]: https://i.stack.imgur.com/pTszw.png

Answer №1

You won't be able to apply the Select Class in Selenium since it isn't a select element.

Instead, utilize driver.findElement with the following xpath:

//div[contains(@class,'dropdown-menu')]/ul/li/a[.='your_option_value']

Then, proceed to click() on the selected option.

Here's an example xpath for the "Know My Numbers" option:

//div[contains(@class,'dropdown-menu')]/ul/li/a[.='Know My Numbers']

Answer №2

To expand the dropdown element, you can start by clicking on it:

 driver.findElement(By.cassSelctor("div#dropdown-menu.ng-scope"));

Once expanded, you can choose an option using the following code:

  driver.findElement(By.cassSelctor("div#dropdown-menu.ng-scope ul li:nth-child(i) a"));

  //Use the index number 'i' to select your desired option from the dropdown.

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

What is the best way to access a dropdown menu by clicking?

IMAGE code driver.find_element((By.XPATH, "//li[contains(@class,'ellipsis1')][1]")).click() error selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: 'using' must be a string if bug code change t ...

How can I retrieve the number of rows in a table using ruby capybara?

When working with Java, we typically utilize the following code: WebElement tableName = driver.findElement(By.xpath("table_xpath")); List<WebElement> rowCount = tableName.findElements(By.tagName("tr")); System.out.println(rowCount.size()); What i ...

Getting the response page after authentication in Selenium requires implementing the appropriate code that handles the authentication

After submitting a form, I am looking to receive a response on the same page with empty form fields. I attempted to use time.sleep(), but unfortunately it did not resolve the issue. from selenium.webdriver.common.desired_capabilities import DesiredCapab ...

Looking for the specified location of the browser binary in Robot Framework in relation to using Firefox

Whenever I run the following command, I encounter this error: Open Browser http://google.com ff SessionNotCreatedException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary& ...

Selenium and Docker: Struggling to load a personalized Chrome user profile

Hey there, I posted an issue a couple of days ago, but it seems like it's not really considered an issue. However, my problem still persists, and I'm hoping someone can help me figure out what's going on :D You can find the detailed discus ...

Executing a protractor test on Safari results in the message "Angular was not located on the webpage https://angularjs.org/"

Recently, I encountered an issue while trying to run a Protractor test on Safari, even when following the official example provided at http://www.protractortest.org/. Below are my conf.js and todo-spec.js files. The problem arises when I set browser.ignor ...

The search button cannot be found by Selenium when using xpath for locating the element

Struggling to locate an element using Selenium's xpath tool? While copying xpaths from other websites works perfectly fine, www.gsc.com.my (a Malaysian cinema booking site) seems to be putting up a fight. Is there a security barrier blocking the butto ...

Logging in using Selenium WebDriver in Java

I'm just starting out with selenium webdriver and I need to automate a webpage for my project. Right now, I'm working on the login page but I'm having trouble with the login button. I'm not sure which locator to use for it. The login bu ...

What is the reason for the python-selenium-webdriver's 'quit' function not properly exiting the program?

My py.test python-selenium test setup involves creating a Firefox webdriver within a py.test fixture. Here's an overview of what I'm doing: 'driver.py': class Driver(object): """ Driver class that includes basic wrappers for t ...

Automating Checkbox Selections with Python Selenium

I'm currently working on scraping data from , but I'm encountering an issue with checkbox selection in my script. Here is a snippet of my code: from selenium.webdriver.common.by import By from selenium.webdriver.support.ui import WebDriverWait ...

Choose various dropdown lists with unique identifiers in Python Selenium

Whenever I attempt to complete a form that features a drop-down menu for each order number. <select name="order(889673519).box(1).shippingmethod" onclick="" onchange="" id="order(889673519).box(1).shippingmethod"><option value="" id="order(8896 ...

Tips for automating Selenium to scrape websites once the page has finished loading

I am utilizing scrapy for crawling all the links and selenium to scrape all the pages. While Selenium was able to scrape most of the pages, it encountered difficulties with a few pages due to slow loading times. I attempted using timeout(), but it didn&ap ...

Is there a way to extract the text from a textarea using webdriver?

When attempting to retrieve the contents of a textarea within an HTML form using webdriver in Python, I am able to get the text, but the newlines are missing. Despite consulting the selenium docs, which provide limited information: class selenium.webdrive ...

Using C# with Selenium webdriver to choose an option from a listbox or dropdown by selecting text

My code efficiently selects an item from a listbox based on its visible text. var selectElement = new SelectElement(TestFramework.FindWebElement(this)); selectElement.SelectByText(text); The issue I am facing is that the text of the items in the listbo ...

Python (selenium) login attempt failure - finding success with v-on:click="submitForm"?

Is Selenium the right module to use for clicking this type of button, or should I be using a different one? Can you provide the related code as well? Any help would be greatly appreciated. Thank you in advance. I'm new to coding and currently learnin ...

Discover the optimal method to test application functionalities with two distinct users using NUnit and C# with Selenium

Looking for an efficient way to test all features on the webpage with two different users - one as an admin and the other as a normal user. Check out this overview of my Selenium tests: The webpage has three distinct features: UnlockInstruction Tac Uplo ...

Utilizing Selenium WebDriver in Python to locate and interact with WebElements

Currently, I am utilizing Selenium for real-time web scraping. However, I am encountering issues searching for a specific WebElement even though the documentation indicates that it is feasible. while True: try: member = self.pdriver.find_all(" ...

Utilizing HTMLUnitDriver with Selenium 3.0.x

In my Maven project, I am currently using selenium-java 3.0.1 and have added selenium-htmlunit-driver 2.52.0 separately to account for the lack of HTMLUnitDriver in this version. However, when running tests, I encounter the following exception: org.open ...

Choose elements using selenium in Python

Is there a way to use Selenium's Select to click on the third option in the first drop-down menu ("Fejlesztési programok") at this website: I attempted using css-selector to locate the menu's id, but it doesn't seem to respond. Any suggest ...

Is there a way to retrieve the present content of an element in webdriver?

I seem to have a misconception about this. I am trying to extract the data from an element, which in this scenario is a form field, on a webpage that I am navigating with Webdriver/Selenium 2 Below is the code I have been using: Element=driver.find_ele ...