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");
Related
Apologies if this question was answered before, I want to click on an area in a browser with plain text using Selenium Webdriver in python
The code I'm using is:
element_plainText = driver.find_elements(By.XPATH, '//*[contains(#class, "WgFkxc")]')
element_plainText.click()
However this is returning "ElementNotInteractableException". Can anyone help me out with this?
Selenium is trying to be helpful here, by telling you why it won't click on the element; ElementNotInteractableException means it thinks that what you're trying to click on isn't clickable.
This usually happens because either:
The element isn't actually visible, or is disabled
Another element is "overlapping" the element, possibly invisibly
You're clicking something Selenium thinks won't do anything, like plain text
There's two things I'd try to get around this. Firstly, Actions. Selenium has an Action API you can use to cause specific UI events to occur. I'd suggest finding the co-ordinates of the text, then making Selenium click those co-ordinates instead of telling it to click the element. Read more about that API here.
Secondly, try clicking it with Javascript, using a Javascript Executor. That can often give you the same outcome as using Selenium directly, without it being so "helpful".
one more problem i hv,i asked similar question earlier and i tried that method but not able use that methon in this problem so pls help me. it's element
html code is - Filters
So basically, question is that there is one button its kind of toggle button and i want click on that button to select device like Desktop, Tablet & Mobile all check boxes are already (default) selected now i have to uncheck or deselect device, to do this, first i have to click on that toggle button , when i click on toggle button its id (gwt-uid-598) 598 is getting changed every time or every refresh. Can you pls help me, what should or which method should i follow in this case.
i am using below python code.
Click on device Filters
elem = driver.find_element_by_xpath('//*[#id="gwt-uid-598"]/div/div/span')
elem.click()
Thanks in advance.
Good question.
Try to use another selector, for example: css class or use xpath method contains().
Example: //div[contains(text(), "checkbox")]
I can help you if you can provide source code of the page or needed element.
As the title says, how can I .click() a button using Selenium, when the button gets "disabled" after using the method clear or send_keys?
Before:
That's the page status when I open it's url... but then right after I run my code to find the textbox and replace it's value, the element gets disabled (maybe by some sort of JS) right after I clear it's content or write something to it using send_keys.
After:
Code:
txt_value = driver.find_element_by_xpath('//input[#id="txtValor4"]')
txt_value.clear() #this disables the button
txt_value.send_keys(str(123,45)) #this also disables the button
My question is:
How can I bypass this website protection and press the Continuar button?
I thought about disabling JS, but the whole website relies on it to produces the requires documents.. wrong alternative.
So I thought about using the button properties to simulate the pressing of the button... just don't know if it's possible, or how I could do this.
Another option was blocking only the JS that disables the button maybe mapping where the command comes from using the inspect element and network tools...
So is there any way to achieve this?
ps.: I can't give the URL because it requires my login data.
Ok, so you can't directly do this through normal means. Selenium WebDriver is made to simulate real use of a browser. It may be possible however to use the execute_script function. (Java Selenium has a built in JavascriptExecutor class, I assume this is python's version.) The execute_script function allows Selenium to perform tasks that a human interacting with a browser can't do.
driver.execute_script("document.getElementById('buttonid').click()")
Or something along those lines should work. Hope that helps you out.
If you don't get any solution with selenium and javascript, you can use Sikuli concept. To click that element, take the image of the 'Continuar' button and save it in resources folder.
String elementImg=Path of the Image;
screen.click(elementImg);
I could bypass this using driver.execute_script("document.getElementById('txtValor4').value = 123.45"), to pass the values into the textbox, so the button didn't got disabled and I could press the Continue button.
Even bypassing this, the result wasn't the expected! The value that I entered was supposed to be corrected by some sort of interest. But bypassing this, the value isn't corrected.
Today the user that asked the program told me that everytime I change the value inside this textbox, I must press the Calculate button.
So, instead of inefficiently bypassing this disable method, I could solve my problem using:
b = driver.find_element_by_xpath('//input[#id="txtValor4"]')
b.clear()
b.send_keys('123.45')
driver.find_element_by_xpath('//input[#id="btnCalcular4"]').click()
driver.find_element_by_xpath('//input[#id="btnContinuar4"]').click()
This way the tax value is corrected by interest and the website generate the .pdf with the exact value that I was expecting.
Many thanks for everyone that put some time and effort trying to help me.
I'm attempting to make a DeviantART Llamabot for a friend as my first Selenium project with Python 3. I have the bot 99% working except for being able to find the "give llama" button.
The problem seems to be that the menu the button appears under is a popup and I can't just right click and select "copy css selector" in Firefox. As soon as I inspect the element for the give menu the menu closes and the html changes.
I've managed to take a screen shot of a random sample page of the code so I can even see what's there. I've tried learning how CSS selectors work from scratch myself and I've managed to find every nested element EXCEPT the actual items in the list. I've tried looking for Nth child and using the ">" operator. I've attempted searching by class name, name, Xpath, link name, partial link name, nothing has worked.
I've read about this problem inspecting popup elements elsewhere and the suggestions are effectively to write an HTML parser or something to copy the entire html code as it changes and then select it from your copy. I'm not going to do that for this project. It's entirely too much work unless I absolutely have to for some reason.
Honestly at this point I don't even care anymore and I just want someone to outright just tell me what to type in so I can finish this project. This is the screenshot I managed to get. I'm looking for the item highlighted in blue.
Since my code was requested for clarification here it is
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.action_chains import ActionChains
binary = FirefoxBinary('C:\Program Files (x86)\Mozilla Firefox\Firefox.exe')
browser = webdriver.Firefox(firefox_binary=binary)
Deviant = browser.get("http://www.deviantart.com/random/deviant")
GiveMenu = browser.find_element_by_css_selector(".i47")
GiveMenu.click()
#GiveLlama = browser.find_element_by_css_selector("")`
Everything except the last line works which is why the last line is commented out until I can figure out what to put in there. No matter what I've tried, including the examples provided by the people answering this question so far, I either get a no such element error or an illegal syntax error.
You can use the xpath selector, in chrome you can use rigth click and click on copy > copy Xpath, or the element selected on your inspector is "div.popup2 .blockmenu a.f.givellama"
You should click the "Give" button first, when the pop up dialog opens, inspect the "Give a Llama Badge" element and identify the xpath. Here is a screen shot.
screen shot to locate "Give a Llama Badge" button
You can find that, the xpath to locate "Give a Llama Badge" button(Should click the Give button first to locate this element).
//a[#class='f givellama']
The xpath to locate "Give button"
//a[#href='#give-give-give']/span[text()='Give']
As you pointed out, when the popup dialog opens, if you try to test the xpath in the browser console via "Firepath" or others, when you type "Enter" or click the left mouse, the popup windows is closed. But don't worry about this, since you already identified the xpath locator, you can debug it in your scripts.
I have an issue when trying to test a web application with Selenium/Python. Basically I can't test elements of a pop-up window.
A scenario: I can test all elements for a page. But when I go to click on a button that opens up a small pop up box I can't test the elements on the popup. It's like the pop up isn't in focus or active.
I can test elements on the next page. For example click a button, brings me on to next page, and I can work with elements on the 'next' page. So it the problem seems to be popup specific.
I could post code but to be honest it might confuse at this stage. I may post code in a later post, thanks
There is a property called switch_to
Q: How do I handle pop up windows?
A: WebDriver offers the ability to cope with multiple windows. This is done by using the WebDriver.switch_to.window(knownName) method to switch to a window with a known name.
If the name is not known, you can use WebDriver.window_handles to obtain a list of known windows.
You may pass the handle to switch_to.window(handleName)
For example I used driverName.switchTo.window(driverName.getWindowHandle()) to get a hold of popups for which I didn't want to look for names.
Additional references:
http://code.google.com/p/selenium/wiki/FrequentlyAskedQuestions
For the Selenium RC API, you need to use the SelectWindow command to switch to the pop-up window. The window can be specified either by its name (as specified on the JavaScript window.open() function) or its title. To switch back to the main window, use SelectWindow(None).