How to handle keyboard and mouse actions using Selenium?

We can handle special keyboard and mouse events by using Advanced User Interactions API. The Advanced User Interactions API contains the Actions and the Action Classes that are needed for executing these events. Most commonly used keyboard and mouse events provided by the Actions class are mentioned below:

  • clickAndHold(): Clicks (without releasing) the current mouse location.
  • dragAndDrop(): Performs click-and-hold at the location of the source element, moves.
  • source, target(): Moves to the location of the target element, then releases the mouse.