How to double click on Web element in Selenium

Answered

Hi,

Can anyone help me with the code for double clicking on a Web element.I tried a lot but couldn’t perform it and its holding my automation work>
I tried below code but its throwing an error,

Actions Useraction = new Actions(driver);
Useraction.moveToElement(driver.findElement(By.xpath(“.//*[@id=’testuser@hcl.com’]/div[2]/div/img”))).doubleClick().build().perform();

Add Comment
2 Answer(s)

Hi Virender,

Sorry for unclear question,here is the Error am getting, And as mentioned in my previous question i was using that code to double click a web element.

Error Massage;

Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’testuser@hcl.com’]/div[2]/div/img”}
Command duration or timeout: 10.19 seconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.45.0’, revision: ’32a636c’, time: ‘2015-03-05 22:01:35′
System info: host: ‘NareshG’, ip: ‘10.154.0.7’, os.name: ‘Windows 7′, os.arch: ‘x86′, os.version: ‘6.1’, java.version: ‘1.7.0_45′
*** Element info: {Using=xpath, value=.//*[@id=’testuser@hcl.com’]/div[2]/div/img}
Session ID: d9a783ed-d335-4afb-9a79-ccfffeacb731
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=WINDOWS, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=38.0.5}]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:204)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:156)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:599)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:352)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:449)
at org.openqa.selenium.By$ByXPath.findElement(By.java:357)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:344)
at automationFramework.DragDropTestCase.main(DragDropTestCase.java:75)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’testuser@hcl.com’]/div[2]/div/img”}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: ‘2.45.0’, revision: ’32a636c’, time: ‘2015-03-05 22:01:35′
System info: host: ‘NareshG’, ip: ‘10.154.0.7’, os.name: ‘Windows 7′, os.arch: ‘x86′, os.version: ‘6.1’, java.version: ‘1.7.0_45′
Driver info: driver.version: unknown
at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/HCL/AppData/Local/Temp/anonymous6560000267399175612webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:10271)
at <anonymous class>.fxdriver.Timer.prototype.setTimeout/<.notify(file:///C:/Users/HCL/AppData/Local/Temp/anonymous6560000267399175612webdriver-profile/extensions/fxdriver@googlecode.com/components/driver-component.js:603)

naresh_g7 Train Answered on June 8, 2015.
Add Comment

Hi Naresh,

Exception clearly states that there is no element present on the web page corresponding to the Xpath locator you have mentioned.

Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”.//*[@id=’testuser@hcl.com’]/div[2]/div/img”}

Get the right locator for the element and the code mentioned in the question will work for you.

Virender

Virender Singh Professor Answered on June 8, 2015.

Thank You Virender….

on June 8, 2015.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.