Selecting a dynamic drop down item in Selenium - python

I have a dynamic drop down menu and I want to select one of the items within it.
I have tried using the Select method but I believe that it doesn't work because the drop down isn't a select item. So instead, I think the solution would be to first click the drop down and then search for the item I want to select.
The drop down looks like this:
The drop down after it's been clicked looks like this:
The HTML code:
I have tried getting my Python script to click the drop down so that it expands but I believe I must be using the wrong ID (s2_id_autogen10_search). Any help or any other solution ideas would be appreciated.
EDIT:
So I am now trying to get Selenium to click the listbox to expand the options. Given the HTML code below, I am trying:
driver.find_element_by_id("select2-results-10").click()
However, it is not working. I receive this error.
selenium.common.exceptions.ElementNotInteractableException: Message: element
not interactable

Related

I have a selenium python issue on select an html element icon and click

I'm trying to click to close a message from a website with selenium. However, when I put it to click, a message appears in the Visual Studio Code console saying that it was not possible to click on the element because it is not a clickable element.
sleep(5)
web.find_element(By.XPATH, '//*[#id="top-container"]/div[1]/div/i').click()
devtool element
error https://i.stack.imgur.com/sgzoE.png
if anyone knows any library that delete the element in devtool. why do i need to remove that message to appear another button to proceed with application
If you look at the error message carefully, it doesn't state that it's not a clickable element. It states that the click was intercepted. In other words, Selenium tried to click on the X to close but another element, an <h3>, got in the way.
It looks like your locator is fine. According to the error message, it looks like it's finding the right element. I personally would change it to
web.find_element(By.CSS_SELECTOR, 'i.icon-remove').click()
because I think it's more readable and less likely to click the wrong element.
I can't see the page so I have no idea what h3 is getting in the way and if it's possible to even remove it. So, if you can't get around the h3, you will likely have to use JS to click the element.
icon = web.find_element(By.CSS_SELECTOR, 'i.icon-remove')
driver.execute_script("arguments[0].click();", icon)
There are different ways to call an element. Let's try the following:
web.find_element(By.ID, "top-container").click()
Please let me know if works, either way we can see other options

Python with Selenium || how to select first option in listbox?

In a constantly updated listbox, I have to select the first tile each time.
This list will be constantly updated and I have to regularly click on the first option.
WebDriverWait(driver,30).until(EC.element_to_be_clickable((By.CLASS_NAME,"dual-listbox__available"))).click()
I can't get a response from your code.
In the above code, you can get the first element by a CssSelector. Find the google chrome extension SelectorsHub so you can get the CssSelector easily which will solve your problem.

How to select an option from dropdown where the value is changing or there is no fixed value?

I wanted to write a selenium python code and try to select a dropdown option on this website, I have tried all the option like, select class, actionchain. But it is not working here, is there any way to select the item from this picture that I have shown. please help me with your reply. Thank you.
[1]: https://i.stack.imgur.com/mRROe.png

Select option in list with Selenium + Python

I'm using Selenium with Python to use this website and want to change page by clicking on the button designed for that. However, and I don't know why, this button is disabled and becomes enabled only if you choose another number of items to be displayed on the page.
I managed to programmatically click on the list to display all the options but didn't manage to select an option.
I tried with the following lines:
driver.find_element_by_xpath("//*[#id='edit-limit']/option[2]").click()
driver.find_element_by_xpath("//select[#id='edit-limit']/option[2]").click()
driver.find_element_by_link_text('50').click()
Does someone know how to solve this issue?
I will give a method for selecting option by value from dropdown list or select:
def set_select_element(self, element, val):
element = ui.Select(element)
return element.select_by_visible_text(val)
where element -- this is your select element on the page.

Select from dropdown using Selenium Python, front end app - react.js

I want to select an item from a drop down using selenium python. The project uses react.js. The dropdown html appears in a div.
code inspect for dropdown
As this is under div, not select, when i try to select specific value, i got an error message.
Error message:
selenium.common.exceptions.UnexpectedTagNameException: Message: Select
only works on elements, not on div
How can I solve this issue?
You cannot use Select class to operate dropdowns which are not implemented using select and option elements.
You have to handle this kind of dropdown "manually" - generally speaking - click it to open it up, locate the desired dropdown item/option and click it. E.g., judging by you concise HTML snippet, to open up the dropdown you can try:
# open up the dropdown
dropdown = driver.find_element_by_css_selector(".Select-control")
# or dropdown = driver.find_element_by_css_selector(".Select-control .Select-input")
dropdown.click()
# TODO: select option
Sometimes, simply focusing the dropdown and typing the desired item/option text would auto-select it - if this is the case, you can try:
from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element(dropdown).send_keys("Desired option text").perform()
And, if there are any animations or time delays (to, for example, retrieve the options from the server) you may need to add Explicit Waits to handle the possible timing issues.
These are all general tips, I am operating under assumptions and I have no way to check if anything above works for your use case.

Categories

Resources