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.
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 –
-
MouseHover action in selenium WebDriver
-
Right Click (Context click) in Selenium
-
Verify Tool Tip Message text using Selenium WebDriver
-
How to Perform series of actions using Actions class in selenium WebDriver?
-
How to use tab button in selenium WebDriver?
-
How to perform Drag and Drop operation using selenium WebDriver?
-
How to send text in capital letters in to a text-box using Actions class in Selenium WebDriver?
-
How to refresh webpage using Action class in selenium WebDriver?
Hope This helps !!!