3

There is a way to click on element by executing javascript like following:

((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);

I want to double click on element by executing javascript, hence I tried like following:

((JavascriptExecutor)driver).executeScript("arguments[0].doubleClick();", element);

But it gives error:

org.openqa.selenium.WebDriverException: unknown error: undefined is not a function

Please tell me what I need to do in order perform double click by executing javascript.

3 Answers 3

6

You should use dblclick event

click, dblclick events

Sign up to request clarification or add additional context in comments.

4 Comments

I receive the execption: arguments[0].dblclick is not a function
@NTDLS Can you give more details?
var row = browser.Driver.FindElement(By.ClassName("profile-row")); browser.JavaScriptExecutor.ExecuteScript("arguments[0].dblclick();", row); Exception: arguments[0].dblclick is not a function
check the following github issue
2

Please try double click with mouse events:

((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);"+ 
    "arguments[0].dispatchEvent(evt);", element);

2 Comments

This worked flawlessly
1

This is the Java code for double click using JsExecutor

public void doubleClickWithJS(WebElement element) {
   JavascriptExecutor executor = (JavascriptExecutor) driver;
   executor.executeScript("arguments[0].dispatchEvent(new MouseEvent('dblclick', { bubbles: true }));", element);
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.