Selenium 2.0 / WebDriver clickAt() method unsupported - selenium

Selenium clickAt() function is throwing "Unsupported" exception while using with WebDriver (WebDriverBackedSelenium or just Selenium 2.x using ChromeDriver).
Is there any way to use this Selenium function via WebDriver?
Adding some code for context ...
ChromeDriver driver = new ChromeDriver();
driver.findElement(By.id("someID")).clickAt("25, 25");
.clickAt() method isn't even recognized ... however, using the WebDriverBackedSelenium is what provides the Unhandled exception.

You have to use Advanced User Interactions API
Click at the specific point inside an element looks like following:
ActionChainsGenerator builder = ((HasInputDevices) driver).actionsBuilder();
Action action = builder
.moveToElement(elementLocator, xOffset, yOffset)
.click()
.build();
action.perform();
At the moment, it is implemented for HtmlUnitDriver and InternetExplorerDriver only, other drivers are work in progress.

I have sometimes had similar problem and have fired the two MouseDownAt & MouseUpAt to solve the issue.. Seems as some JavaScript don't fire ok with clickAt always

Before you use click command on locator. you should use mouseOver on it.
Normally. this problem happen when link that need to click hidden or invisable.

Related

How to resolve org.openqa.selenium.WebDriverException?

I am writing an automated test and want to report bugs, if occur, directly in the repo at GitHub. The step which fails in my program is the Submit new issue button from GitHub Issue Tracker.
Here is the code:
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
And the exception:
org.openqa.selenium.WebDriverException: Element is not clickable at
point (883, 547.7999877929688). Other element would receive the click:
div class="modal-backdrop"></div
The following command also does not work:
((JavascriptExecutor) driver).executeScript("arguments[0].click();", sendIssue);
How can I make it clickable? Is there any other way by which I can resolve this issue?
This is happening because when selenium is trying to click ,the desired element is not clickable.
You have to make sure that the Xpath provided by you is absolutely right.If you are sure about the Xpath then try the following
replace
WebElement sendIssue = driver.findElement(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button"));
sendIssue.click();
with
WebElement sendIssue =(WebElement)new WebDriverWait(DRIVER,10).until(ExpectedConditions.elementToBeClickable(By.xpath("/html/body/div[5]/div/div/div[2]/div[1]/div/form/div[2]/div[1]/div/div/div[3]/button")));
sendIssue.click();
If that doesn't work ,You will get an Timeout exception, In that case try incaresing the timeout amount from 10 to 20.
If it still doesn't work please post a screenshot of the HTML.
You need to write something in the issue title and description to make the issue clickable are you sure you are not making that mistake of clicking the button without writing anything in those places I am adding screenshot for your convenience.
Selenium Webdriver introduced in a previous version (v2.48) a new behavior that prevent clicks on elements that may be overlapped for something else (a fixed header or footer - for example) or may not be at your viewport (visible area of the webpage within the browser window).
You can see the debate here.
To solve this you will need to scroll (up or down) to the element you're trying to click.
One approach would be something like this post:
Page scroll up or down in Selenium WebDriver (Selenium 2) using java
Another, and maybe more reasonable, way to create a issue on Github, would be using their API. Maybe it would be good to check out!
Github API - Issues
Gook luck.
This worked for me. Instead of HTML browser this would be useful if we perform intended Web Browser
// Init chromedriver
String chromeDriverPath = "/Path/To/Chromedriver" ;
System.setProperty("webdriver.chrome.driver", chromeDriverPath);
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200","--ignore-certificate-errors");
WebDriver driver = new ChromeDriver(options);

Selenium Webdriver: how to drag element to another iframe?

I am using Selenium chrome webdriver with java, I need help dragging an element out of an iframe and onto another element in a different iframe. Has anyone done this before and if so could you post an example for me?
Here is what I've tried so far, also I have tried many other solutions:
WebElement Atom = driver.findElement(By.xpath("//*[text()='Circle']"));
driver.switchTo().defaultContent();
driver.switchTo().frame("treeNavigation");
WebElement Event = driver.findElement(By.xpath("//*[text()='Line']"));
// Create Actions object passing in a WebDriver object
Actions builder = new Actions(driver);
// Chain some calls together and call build
Action dragAndDrop = builder.clickAndHold(Atom)
.moveToElement(Event)
.release(Event)
.build();
// Perform the actions
dragAndDrop.perform();
Haven't done that yet, but I would like to try the following;
move to the source iframe, get the element, clickAndHold, build, perform. Then switch to default content, then switch to target iframe, moveToElement, release, build, perform.
Any sample test page would help. Thanks.

Access new window elements through selenium RC

I am new to Selenium. This is my first attempt. And I want to access the Elements in the new window through Selenium RC. I have a page with a hyper link clicking on it will open new page. I want to enter username and password elements in the new window. Html Code is
Employee Login
and the new page elements are "emailAddress" and "password" for login.
My selenium code is
public static void main(String args[]) throws Exception
{
RemoteControlConfiguration rc=new RemoteControlConfiguration();
rc.setPort(2343);
SeleniumServer se= new SeleniumServer(rc);
Selenium sel=new DefaultSelenium("localhost",2343,"*firefox","http://neo.local/");
se.start();
sel.start();
sel.open("/");
sel.windowMaximize();
//sel.wait(1000);
sel.click("empLogin");
//sel.wait(2000);
//sel.openWindow("http://myneo.neo.local/user/login", "NewNeo");
//sel.waitForPopUp("NewNeo", "1000");
//sel.selectWindow("id=NewNeo");
Thread.sleep(20000);
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
}
First I tried with normal approach, where it failed to identify the elements. Then I tried with open window and selectWindow options, where it through errors like
"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Window locator not recognized: id
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.DefaultSelenium.selectWindow(DefaultSelenium.java:377)
at Demo.main(Demo.java:24)"
Some one told me that it is not possible with Selenium RC. It can achieved through Selenium Webdriver only. Is it true?
Please Help,
Thanks in Advance.
Selenium RC is not maintained anymore, I would recommend you to use WebDriver instead. Selenium RC is a Javascript application where as WebDriver uses browsers Native API. Therefore browser interactions using WebDriver are close to what the real user does. Also WebDriver's API is more intuitive and easy to use in my opinion. I don't see HTML in your question, but you could do start with something like this,
WebDriver driver = new FirefoxDriver();
WebElement login = driver.findElement(By.id("empLogin"));
login.click();
I will say, do as #nilesh stated. Use Selenium WebDriver.
Answer to your specific problem though:
You are failing at this line because you are not specifying a selector strategy.
sel.click("empLogin");
If the id attribute is empLogin then do
sel.click("id=empLogin");
There are other selector strategies you can use:
css=
id=
xpath=
link=
etc...
You can see the full list here.
You will also fail here due to the same issue:
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
Put a selector strategy prefix before those fields.
sel.type("name=emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("name=password", "xxxxxxxx");

Mouse doubleclick not work in textbox using Selenium WebDriver

I try to double click on the text box by which the text will be selected.....The code looks like
WebDriver driver=new FirefoxDriver();
driver.manage().window().maximize();
driver.get("https://www.facebook.com/");
WebElement txtBoxElement=driver.findElement(By.xpath("//*[#id='email']"));
txtBoxElement.sendKeys("abc");
System.out.println("Test start");
Actions builder=new Actions(driver);
Action a=builder.moveToElement(txtBoxElement).doubleClick(txtBoxElement).build();
a.perform();
//This is for another way to double click on the text field
Locatable locatable = (Locatable) driver.findElement(By.name("email"));
Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.mouseMove(locatable.getCoordinates());
mouse.doubleClick(locatable.getCoordinates());
System.out.println("Test Complete");
}
but both of this way was not working I bypass this problem using this
Action a=builder.moveToElement(txtBoxElement).sendKeys(txtBoxElement,Keys.chord(Keys.CONTROL,"a")).build();
a.perform();
my question is why double click is not working?
I also try this for google search textbox it was also not working.
Here I want to mention one thing that I use Selenium 2.37 and firefox 26 .
I did not get any error but not double click on this element.I also observe that if I commented out the txtBoxElement.sendKeys("abc"); part and then sendkeys using Actions event,it write the text on browser address bar.
I believe you must be seeing following error while double clicking an element:
Cannot perform native interaction: Could not load native events component.
This is always issue with latest version of Firefox with latest verion of Selenium WebDriver(For more details please refer to link).
You can resolve this issue by downgrading Firefox from 26 to 25. With Firefox 25 your code will work.
It may be that you have the Action statement incorrect for the double-click. I did a double-click with simple statements like this:
Actions a = new Actions(driver);<br>
a.doubleClick(txtBoxElement);<br>
a.perform();
If you are trying to select all of the text in the text box try:
WaitUntil.elementReady(driver, 2,".//span[#class='scale-input-box']/input").sendKeys(Keys.CONTROL + "a");
To overcome problems with doubleclicking in Selenium try Alternative workaround Source
Simplified to this:
((JavascriptExecutor) driver).executeScript("document.getElementById('map_container').dispatchEvent(new Event('dblclick'));");

Selenium clicking a button

I am trying out selenium for the 1st time and I have a quick question. When I call the click() method on a WebElement, I noticed that it is a void type method. So does the HtmlUnitDriver hold the updated page that is rendered after the click() happens?
Yes. The WebDriver interface is controlling the browser, however it's still the browser (in your case, HtmlUnit) that does most of the work and remembers the state of teh page etc.
Therefore, WebDriver as such doesn't really have a state (an overly simplified statement, but true for your purpose). When you send a click() command, it performs it in the browser, than waits for the browser to complete its job (load the new page), then again waits for your commands on the new page.
WebDriver always operates on what the browser currently has.
I can see from your question that you are using HtmlUnitDriver. JavaScript is disabled in this driver by default (for explanation click here). This driver uses the Rhino JavaScript engine and is not used in any of the popular browsers. This might explain why the actions you are trying work fine in Firefox but not in Selenium.
You could try enabling JavaScript in HtmlUnit as follows:
HtmlUnitDriver driver = new HtmlUnitDriver();
driver.setJavascriptEnabled(true);
But instead I would recommend using FirefoxDriver.
WebDriver driver = new FirefoxDriver();
This should emulate the behavior you're seeing when you navigate through the webpages yourself.