Chapter 14: action class in selenium webdriver

Action class in selenium webdriver

For performing complex user interaction like drag and drop, we have an Actions class in Selenium WebDriver. Using the Actions class, we build a sequence of whole events and then perform it using Action (an interface which represents a single user-interaction).

Selenium has the built-in ability to handle various types of keyboard and mouse events.we use the selenium actions class rather than using the Keyboard or Mouse directly. These includes actions such as drag and drop, clicking multiple elements.Handling of special keyboard and mouse events are done using the Advanced User Interactions API. It contains the Actions and the Action classes that are needed when executing these events. The different methods of Actions class are-

clickAndHold(WebElement element) – Clicks a web element at the middle(without releasing).

  • moveToElement(WebElement element) – Moves the mouse pointer to the middle of the web element without clicking.
  • release(WebElement element) – Releases the left click (which is in pressed state).
  • build() – Generates a composite action.