</>

Technology

Selenium

Difficulty

Intermediate

Interview Question

How to perform double click in Selenium?

Use Actions.doubleClick(element) to simulate a double-click mouse event on a web element.

Answer

Use Actions.doubleClick() to simulate a double-click event.

Basic double click:

Java
WebElement element = driver.findElement(By.id("editableField"));
Actions actions = new Actions(driver);
actions.doubleClick(element).perform();

Double click then verify:

Java
WebElement label = driver.findElement(By.id("editableLabel"));
Actions actions = new Actions(driver);
actions.doubleClick(label).perform();

WebElement input = driver.findElement(By.cssSelector("#editableLabel input"));
input.sendKeys("new text");

Common use cases:

  • Double-click to edit inline table cells
  • Double-click to open files in a file manager component
  • Double-click to select a word in a text editor

Note: doubleClick(element) is equivalent to moveToElement(element).doubleClick() — both achieve the same result.

Follow AutomateQA

Related Topics