Read the complete Blog - How to use Actions Class in Selenium
In this article, you will learn about the Actions class and their example. Selenium provides different methods to perform click, input text, and select from dropdowns and tables. However, there are such complex actions that we need to perform like drag and drop, double click, right-click, and, many more. These actions can not be handled by simple web element commands. To handle those types of action, selenium provides Actions Class. Actions class is used to handle Keyboard
and Mouse
events.
Methods | Description |
---|---|
clickAndHold() | Clicks an element without releasing it. |
contextClick() | Performs Mouse right-click on a given element |
doubleClick() | Performs double click on a given element |
dragAndDrop(source, target) | Click and hold the source element and move to the target location and then release |
sendKeys() | Sends a series of Keys to the given element. |
keyDown(KEY) | Perform press the given KEY and do not release.KEY – Keys.ALT, Keys.SHIFT, Keys.CONTROL, etc. |
keyUp(KEY) | Perform release of the given KEY. |
moveByOffset(X-offset, Y-offset) | Moves the mouse to the given offset (X, Y) |
moveToElement(WebElement) | Moves the mouse to the middle of the given element. |
git clone https://github.com/TestingWithSK/selenium-actions-demo.git
You can find the KeyboardActions class inside
src/test/java/actionTests
. There you can see all the possible Actions methods are given.
You can find the MouseActions class inside
src/test/java/actionTests
. There you can see all the possible Actions methods are given.
- Right click on any java file inside
src/test/java/actionTests
and select -Run '<FILE_NAME>'
Read the complete Blog - How to use Actions Class in Selenium
Happy Testing!!!