How to Double Click an element in Selenium WebDriver?

During automation we will face certain scenarios where in we need to Double click on an element.

To perform these automation steps, Selenium has provided an actions class. Using this actions class we can automate Double click on an element.

Steps to Double Click on an Element in Selenium WebDriver :

  1. Start writing code in an Java file.
  2. First let’s launch the browser (say using chrome here in the example).
  3. Enter the Appliction under test(AUT) url in the browser.

driver.get(“”);

  1. Maximize the browser window.

driver.manage().window().maximize();

  1. In this exmple we are going to double click on an button twice. Hence we need to identify the xpath of the element.

WebElement doubleClickButton = driver.findElement(By.xpath(“//button[@ondblclick=’myFunction()’]”));

  1. Create an object action class and pass the driver reference.

Actions action = new Actions(driver);

  1. Later use the predefined method of action to double click on the element.

doubleClick(doubleClickButton)

here the doubleClickButton refers to xpath of the button that we wanted to double click.

  1. Lets completely build the double click command with reference to action class(i.e action) to open the popup window.

actions.doubleClick(doubleClickButton).perform();

doubleClickButton refers to the locator that we are using to double click in the webpage.

Code Snippet :

Leave a Comment

Your email address will not be published.