Action Class in Selenium

In this tutorial you will see, How can you use Action class in Selenium to manage the keyboard and mouse events in Selenium.

To handle the mouse movements and keyboard events we use Actions class in selenium. Actions class have multiple methods, We will see the uses of important methods.


Action Class in Selenium

To use Actions class in our code, First we need to create the object of the Actions class.

Actions actions = new Actions(driver);


Let’s see the use of Actions class methods and their declaration.

1. clickAndHold() – Clicks without releasing the current mouse location.


2. contextClick() – Performs a context-click at the current mouse location.

Actions action = new Actions(driver).contextClick(element);;


Video Tutorial:

If you liked this video, then please subscribe to our YouTube Channel for more video tutorials.


3. doubleClick() – Performs a double-click at the current mouse location.


4. dragAndDrop(source, target) – Performs click-and-hold at the location of the source element, moves to the location of the target element, then releases the mouse.


5. dragAndDropBy(source, x-offset, y-offset) – Performs click-and-hold at the location of the source element, moves by a given offset, then releases the mouse.


6. keyDown(modifier_key) – Performs a modifier key press. Does not release the modifier key – subsequent interactions may assume it’s kept pressed.

i.e Keys.ALT, Keys.SHIFT, or Keys.CONTROL


7. keyUp(modifier _key) – It performs a key release.

i.e Keys.ALT, Keys.SHIFT, or Keys.CONTROL


8. moveToElement(Element) – Moves the mouse to the middle of the element.


9. release() – Releases the depressed left mouse button at the current mouse location.


10. sendKeys() – ends a series of keystrokes onto the element.


So, all above-mentioned methods are the important methods in the action class. We will see the use of all these methods in the coming tutorials.

0 Comment

Leave a Reply