Actions and Action classes

Actions and Action classes are used for handling keyboard and mouse events. For example, Mouse events includes like mouse over, mouse move, mouse out, mouse hover, mouse release, mouse moving to x and y coordinates on screen, etc and keyboards events like key down,key up and sendKeys.

Below are the most commonly used methods provided in Actions class:
Method Roles
clickAndHold() It clicks at the current mouse location on webpage.
dragAndDrop(source, target) It performs click and hold at the location of the source element and moves to the location of the target element then releases the mouse over that.
source- Select the source element.
target- Element to move to and release the mouse at.
dragAndDropBy(source, x-offset, y-offset) It performs click and hold at the location of the source element and moves by a given offset, then releases the mouse.
source- Select the source element.
xOffset- Acts as a horizontal move offset.
yOffset- Acts as a vertical move offset.
doubleClick() It performs double click at the current mouse location.
keyDown(key) It performs a key press.
key – Any of the keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)
keyUp(key) It performs a key release.
key – Any of the keys (Keys.ALT, Keys.SHIFT, or Keys.CONTROL)
moveByOffset(x-offset, y-offset) Moves the mouse from its current position (or x-offset- horizontal offset, y-offset- vertical offset) by the given offset.
moveToElement(toElement) It moves the mouse to the middle of the element.
toElement- An element where we need to move to.
release() It releases the pressed left mouse button at the current mouse location
sendKeys(onElement, charsequence) It sends a series of keystrokes onto the element.
onElement – Acts as an element that will receive the keystrokes, usually a text field
charsequence – Any string value representing the sequence of keystrokes to be sent