Selenium Webdriver Tutorials

Double click event in Selenium Webdriver using Actions class

In earlier post, we learnt how to replicate (or automate) keyboard and mouse actions in Selenium Webdriver. Selenium Webdriver provides an Advanced User Interaction API (including Actions class) which facilitate user actions to be performed in an application, i.e. users can use this API to simulate keyboard and mouse actions in Selenium Webdriver. In this tutorial we will see how to simulate Double click event in Selenium Webdriver using Actions class.

import org.openqa.selenium.interactions.Actions;

Double click event in Selenium Webdriver

Actions class in Selenium Webdriver

The Actions class is a user-facing API for emulating complex keyboard and mouse actions in Selenium Webdriver. You can directly use this class rather than using the input devices, i.e. Keyboard or Mouse. It Implements builder pattern, in which a complex object is constructed, i.e. builds a “Composite Action” containing all actions specified by the individual method calls. For e.g. Composite Action: Mouse Hover >> Click.

public class Actions extends java.lang.Object

  • Import the package to access the actions class methods.
  • Create the actions class object
  • Access the range of available methods.

The Actions class provides doubleClick() method to perform Double click event in Selenium Webdriver on any specified location or on any identified web element.

  • public Actions doubleClick() — Performs a double-click at the current mouse location.
  • public Actions doubleClick(WebElement onElement) — Performs a double-click at middle of the given element (onElement)

Double click event in Selenium Webdriver

Open Browser and Website

The code below will open the Chrome browser & then api.jquery.com URL.

Switch to Frame

Earlier we learnt that the element in question might be present within a frame. And when writing a test against them, you can easily get tripped if you’re not paying attention. You cannot directly identify an element present in an iFrame. First we have to switch to the frame (optionally scroll the element into view) and then we can identify the elements present using normal Selenium locators.

Double click event in Selenium Webdriver

As stated earlier, the Actions class provides doubleClick() method to perform double click event in Selenium Webdriver on any specified location or on any identified web element.

Actions class in Selenium provides a lot of features which can be used to simulate keyboard or mouse interactions. Some web applications might require you to double click on an element to fire the action. Hope this article helped you in understanding how to automate double click event in Selenium Webdriver. If yes, don’t forget to share it with your friends and colleagues!

Leave a Reply

Your email address will not be published. Required fields are marked *