What is actions class in Selenium WebDriver?

Actions class in Selenium WebDriver –

In Webdriver, handling keyboard events and mouse events (including actions such as Drag and Drop or clicking multiple elements With Control key) are done using the advanced user interactions API . It contains Actions and Action classes which are needed when performing these events.

In order to perform action events, we need to use org.openqa.selenium.interactions.Actionsclass.
We need to use perform() to execute the action.
Using Action API, keyboard interactions are simple to do with webdriver. In Advanced User Interactions API, interaction with element is possible either by clicking on element or sending a Keys using sendKeys()
To use mouse actions, we need to use current location of the element and then perform the action.
The following are the regularly used mouse and keyboard events:
Method :clickAndHold()
Purpose: Clicks without releasing the current mouse location

Method : contextClick()
Purpose: Performs a context-click at the current mouse location (double click).

Method: doubleClick()
Purpose: Performs a double click at the current mouse location

Method: dragAndDrop(source,target)
Parameters: Source and Target
Purpose: Performs click and hold at the location of the source element and moves to the location of the target element then releases the mouse.

Method : dragAndDropBy(source,x-offset,y-offset)
Parameters: Source, xOffset – horizontal move, y-Offset – vertical move Offset
Purpose: Performs click and hold at the location of the source element moves by a given off set, then releases the mouse.

Method: keyDown(modifier_key)
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONROL)
Purpose: Performs a modifier key press, doesn’t release the modifier key. Subsequent interactions may assume it’s kept pressed

Method: keyUp(modifier_key)
Parameters: Modifier_key (keys.ALT or Keys.SHIFT or Keys.CONROL)
Purpose: Performs a key release.

Method: moveByOffset(x-offset, y-offset)
Parameters: X-Offset , Horizontal offset, a negative value means moving the mouse to left side.
Y-Offset, vertical offset, a negative value means moving the mouse to up.
Purpose: Moves the mouse position from its current position by the given offset.

Method: moveToElement(toElement)
Parameters: toElement – Element to Move to
Purpose: It moves the Mouse to the middle of the element.

Method: release()
Purpose: It releases the left mouse button at the current mouse location.

Method: sendKeys(onElement, charSequence)
Parameters: onElement, which will receive the keyStrokes, usually text field.
charsequence- any string value representing the sequence of keyStrokes to be sent.
Purpose: It sends a series of keyStrokes onto the element

As mentioned above, we can use Actions class for following actions –

Hope This helps !!!

Leave Comment

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

Looking for learning Framework Development from Scratch? Lookout for Detailed Framework Development videos on YouTube here -

https://www.youtube.com/automationtalks

Get the Framework code at Github Repo: https://github.com/prakashnarkhede?tab=repositories