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

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.

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

Selecting a dynamic drop down item in Selenium

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

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.

Selenium (python) switching to popup panel

I am trying to use Selenium with Python to click on a text field, which opens a pop-up panel, select the text entry area of that popup, and enter text to it.
switch_to_window and switch_to_frame don't seem to be working. In a previous question I asked about Selenium, someone told me to pause the program until the element I need is available. The solution worked for that problem, but not this one, so I'm assuming I have a different issue and I'm too new to Selenium to understand what it is.
This is what the original box I'm trying to click on looks like:
And the Inspect Element for this box:
When that description box is clicked, it should open this window:
And select this element to enter text into:
So in my code I have:
descriptionBox = driver.find_element_by_id('kiadvany_fulszoveg_text')
descriptionBox.click()
That does not error the program, but it also doesn't seem to actually be clicking on that element. To make matters more confusing, I got this to work exactly ONCE, where it opened the correct Description text box as pictured above, but it has since not worked at all even when I try the exact same thing.
The panel's ID is:
As I mentioned, switching to this panel ID using switch_to_frame or switch_to_window was the first thing I tried, but I'm getting a No Such Element error.
Because I saw the description box open correctly once, but never again, I'm assuming that's where the problem is. I wish, the one time it did pop up, that I'd tried to put the text into the field to see if that would work too, but I hadn't gotten there yet at that point, so I don't know if that would have worked.
Thank you in advance to anyone who can help with this!
Try this
descriptionBox = driver.find_element_by_id('kiadvany_fulszoveg_text')
driver.execute_script('arguments[0].click();', descriptionBox)
or
actions = ActionChains(driver)
actions.move_to_element(descriptionBox)
actions.click(descriptionBox)
actions.perform()

Mouse the focus to an object using selenium python

I am automating a website using selenium RC and python 2.7 on Ubuntu Linux. Here is what I need to do:
Go to the site http://borro.com.
Scroll down to the bottom of the page using key down native command
I need to hover the mouse on g +1
read the tool tip
click on the name that appears in the tool tip.
The problem I am having is -- I need the mouse to physically move there, wait for say 2 secs and then read the tool tip and click on the name
The mouse is not physically moving there and I think the focus is lost and it says element xpath not found.
We've solved a lot of our focus issues by sending a blank key to the element so it gets focused. In this case, you'd probably want to send blank key to the tooltip as soon as it appears. I'm familiar with webdriver but not RC, but RC should have something like send_key(element_xpath, " ") as well.
To get the tooltip's xpath, you can use firebug, and in the console, use something like
$x("//*[contains(text(), 'Publicly recommend this as')]")
to make sure this element is found and xpath is correct. I also recommend not using wildcard characters, so once you find the tooltip's xpath, try to replace the * by the actual element type.
Button Xpath and on hover on button xpath are given below
Actions builder = new Actions(driver);
WebElement tagElement = driver.findElement(By.id("button"));
builder.moveToElement(tagElement).build().perform();
/html/body/div/div/table/tbody/tr/td/div
Try:
selenium.mouseOver("mylocator");

Categories

Resources