Double click in Selenium using Actions class

Initially, we need to instantiate an object of Actions class by passing the driver instance as a parameter Using find element command, we need to find the locator of an element that we want to double click Using the pre-defined double click method of Actions class, we need to perform double click operation on the web element

Right-click in Selenium

Right click action in Selenium web driver can be done using Actions class. Right Click operation is also called Context Click in Selenium. Pre-defined method context click provided by Actions class is used to perform right click operation. Below is the code to demonstrate right click operation using Actions class.

Example of Double Click

Test Scenario

Launch the URL: http://demo.guru99.com/test/simple_context_menu.html Double click on the button labelled ‘Double-Click Me To See Alert’ Click on OK button on the displayed alert

Code: Result: The button labeled “Double-Click Me to See Alert” is clicked and pop-up is shown

In Eclipse, you see the output in the console

Right Click Example

Test Scenario:

Launch the URL: http://demo.guru99.com/test/simple_context_menu.html Perform Right Click operation on the button : right click me Click on Edit link on the displayed list of right click options Click on OK button on the alert displayed Close the browser

Code: Result:

Summary:

Actions class in Selenium is mostly used to perform complex keyboard and mouse operations. Hence, Actions class is preferred compared to Javascript for performing operations such as Right Click and Double Click in Selenium. Right click operation is mostly used when performing right click on an element opens a new menu. Right click operation in Selenium web driver can be done using the pre defined command Context Click as mentioned below Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID (“Element ID”)); action.contextClick(link).perform();

Double click operation is used when the state of web element changes after double click operation. Double Click operation in Selenium web driver can be done using the pre defined command Double Click as mentioned below Actions action = new Actions(driver); WebElement link = driver.findElement(By.ID (“Element ID”)); action. doubleClick (link).perform();