How to doubleClick with WebDriver?

3,161 views
Skip to first unread message

Kai

unread,
Feb 15, 2011, 3:32:14 PM2/15/11
to webdriver
Hi All,

I thought this would be an easy thing to do, but it seems like there
is no support in WebDriver to perform a doubleClick?

I read other posts and tried to execute javascript or call Selenium's
double click but nothing worked. Is there a doubleClick for the
WebElement? Some help would be greatly appreciated. I am working with
an ExtGWT web-app and I have no option but to perform a double click.

Attempts to double click that did not work:

((JavascriptExecutor) driver)
.executeScript(
"var evt = document.createEvent('MouseEvents');
evt.initMouseEvent('dblclick', true, true, window, 0, 0, 0, 0, 0,
false, false, false, false, 0, null);
arguements[0].dispatchEvent(evt);",
myElement);

Selenium selenium = new WebDriverBackedSelenium(driver,
myUrl);

bp

unread,
Feb 16, 2011, 11:29:49 AM2/16/11
to webdriver
did you look at the advanced interactions api in webdriver? It is
documented at

http://code.google.com/p/selenium/wiki/AdvancedUserInteractions

Binken

unread,
Feb 16, 2011, 8:12:24 PM2/16/11
to webd...@googlegroups.com
Advanced interactions I think it's not available in all the Driver

Kai

unread,
Feb 16, 2011, 11:18:53 PM2/16/11
to webdriver
Thanks for introducing me to Advanced interactions!

I did try the following, but currently they both throw an unsupported
exception when using any of the drivers that extend RemoteWebDriver.
Looks like HTMLUnitDriver does implement it, but can't really use that
for my login-based web-app. Hopefully it gets implemented soon! :) Or
if anyone knows any other solution, I would love to hear. Thanks.

Mouse mouse = ((HasInputDevices) driver).getMouse();
mouse.doubleClick(myElement);

OR

Action action = new
ActionChainsGenerator(driver).doubleClick(myElement).build();
action.perform();

mindxp

unread,
Feb 16, 2011, 10:45:15 AM2/16/11
to webdriver
Hi Kai,

Following script help me to double click with Webdriver (hope it will
help you)

if (document.createEventObject){
return arguments[0].fireEvent('ondblclick');
}else{
var evt = arguments[0].ownerDocument.createEvent('MouseEvents');
evt.initMouseEvent('dblclick',true,true,
element.ownerDocument.defaultView,1,0,0,0,0,false,
false,false,false,1,null);
return !element.dispatchEvent(evt);

Wenwen Zhou

unread,
Jun 12, 2014, 2:21:28 PM6/12/14
to webd...@googlegroups.com
You can create an instance of webdriver.ActionSequence,
and then register a sequence of mouse or keyboard action, like doubleClick,
then run perform().

This works in javaScript.

Reference:

Thanks

在 2011年2月15日星期二UTC-8下午12时32分14秒,Kai写道:
Reply all
Reply to author
Forward
0 new messages