Actions Class in Selenium WebDriver
The Actions class in Selenium WebDriver is used to perform advanced user interactions such as mouse movements, clicks, double-clicks, right-clicks, drag and drop, hover actions, keyboard combinations, scrolling, and other complex gestures. It is especially useful when normal WebElement methods are not sufficient to reproduce real user interactions.
Selenium's Java Actions API provides a builder-style approach for creating complex user gestures. It supports pointer, keyboard, and wheel-based interactions and allows multiple operations to be combined into a single action sequence.
Course Resource: Selenium Training Course | Register for Course Demo
1. What is the Actions Class?
Actions is a Selenium class available in the org.openqa.selenium.interactions package. It is designed to automate complex interactions involving mouse, keyboard, and wheel operations.
import org.openqa.selenium.interactions.Actions;
The Actions class is commonly used for testing hover menus, drag-and-drop components, sliders, double-click elements, right-click context menus, keyboard shortcuts, rich text editors, scrolling interfaces, and other interactive web components.
2. Why is the Actions Class Required?
Basic Selenium methods such as click(), sendKeys(), and getText() are sufficient for many normal web elements. However, modern web applications contain many components that require realistic mouse and keyboard interactions.
- Mouse hover menus
- Drag-and-drop components
- Sliders
- Double-click elements
- Right-click context menus
- Keyboard shortcuts
- Multiple-key combinations
- Mouse movement
- Scrolling
- Complex interaction sequences
3. Actions Class Package
The Actions class belongs to the Selenium interactions package.
org.openqa.selenium.interactions.Actions
The interactions package also contains APIs related to actions, pointer input, keyboard input, wheel input, and low-level interaction sequences.
4. Importing the Actions Class
import org.openqa.selenium.interactions.Actions;
5. Creating an Actions Object
The Actions class requires a WebDriver instance.
Actions actions = new Actions(driver);
Here:
Actions is the Selenium interaction class.
actions is the object used to create interaction sequences.
driver is the active WebDriver instance.
6. Basic Actions Class Syntax
Actions actions = new Actions(driver);
actions
.moveToElement(element)
.click()
.perform();
The interaction sequence is constructed using chained methods and executed using perform().
7. Understanding perform()
perform() is one of the most important methods when working with the Actions class. It executes the action sequence that has been constructed.
actions
.moveToElement(element)
.click()
.perform();
A common mistake is to create an action chain but forget to execute it with perform().
8. Actions Class Working Flow
WebDriver
|
v
Actions Object
|
v
Create Action Sequence
|
+----------------------+
| |
v v
Mouse Actions Keyboard Actions
| |
+----------+-----------+
|
v
perform()
|
v
Browser Interaction
|
v
Application State
9. Types of Actions
| Action | Purpose |
| click() | Performs a mouse click. |
| doubleClick() | Performs a double-click. |
| contextClick() | Performs a right-click. |
| clickAndHold() | Presses and holds the mouse button. |
| release() | Releases a held mouse button. |
| moveToElement() | Moves the mouse to an element. |
| moveByOffset() | Moves the mouse by X/Y offsets. |
| dragAndDrop() | Drags an element to another element. |
| dragAndDropBy() | Drags an element by specified offsets. |
| keyDown() | Presses and holds a keyboard key. |
| keyUp() | Releases a keyboard key. |
| sendKeys() | Sends keyboard input. |
| scrollByAmount() | Scrolls by specified X/Y amounts. |
| scrollToElement() | Scrolls until an element is brought into view. |
| pause() | Adds a pause to an action sequence. |
10. Mouse Actions
The Actions class provides several methods for simulating mouse interactions. These include clicking, double-clicking, right-clicking, hovering, dragging, holding, releasing, and moving the pointer.
11. click()
The click() method performs a left mouse click.
actions.click().perform();
It can also be used with a specific element.
actions.click(button).perform();
12. click(WebElement)
WebElement button = driver.findElement(
By.id("submit")
);
Actions actions = new Actions(driver);
actions.click(button).perform();
13. clickAndHold()
clickAndHold() presses the mouse button without immediately releasing it.
actions.clickAndHold(element).perform();
This is especially useful for drag-and-drop operations, sliders, drawing interfaces, and other components requiring a continuous mouse press.
14. release()
The release() method releases a previously held mouse button.
actions.release().perform();
A common interaction sequence is:
actions
.clickAndHold(source)
.moveToElement(target)
.release()
.perform();
15. moveToElement()
The moveToElement() method moves the mouse pointer to an element.
WebElement menu = driver.findElement(
By.id("products")
);
actions.moveToElement(menu).perform();
This method is frequently used for hover menus.
16. Mouse Hover
Mouse hover is required when an element or submenu becomes visible only after the pointer moves over another element.
WebElement productsMenu = driver.findElement(
By.id("products")
);
actions
.moveToElement(productsMenu)
.perform();
17. Hover and Click Submenu
WebElement products = driver.findElement(
By.id("products")
);
WebElement electronics = driver.findElement(
By.id("electronics")
);
actions
.moveToElement(products)
.moveToElement(electronics)
.click()
.perform();
18. Hover Menu Automation Flow
Locate Main Menu
|
v
Move Mouse to Menu
|
v
Wait for Submenu
|
v
Move Mouse to Submenu
|
v
Click Submenu
|
v
Validate Result
19. Double Click
The doubleClick() method performs a double-click at the current pointer location or on a specified element.
actions.doubleClick(element).perform();
20. Double Click Example
WebElement file = driver.findElement(
By.id("file")
);
Actions actions = new Actions(driver);
actions.doubleClick(file).perform();
This can be useful when double-clicking opens, edits, selects, or expands an item.
21. Right Click / Context Click
The contextClick() method performs a right-click.
actions.contextClick(element).perform();
22. Context Menu Example
WebElement document = driver.findElement(
By.id("document")
);
actions.contextClick(document).perform();
The application may then display a custom context menu.
23. Selecting an Option from Context Menu
WebElement document = driver.findElement(
By.id("document")
);
WebElement rename = driver.findElement(
By.id("rename")
);
actions
.contextClick(document)
.moveToElement(rename)
.click()
.perform();
24. moveByOffset()
moveByOffset() moves the mouse pointer relative to its current position.
actions
.moveByOffset(100, 50)
.perform();
100 represents the horizontal X offset.
50 represents the vertical Y offset.
25. Negative Offset
Negative values can be used to move the pointer left or upward.
actions
.moveByOffset(-100, -50)
.perform();
26. moveToElement with Offset
An offset can also be specified relative to an element.
actions
.moveToElement(element, 20, 10)
.perform();
This can be useful when a specific location inside an element must be targeted.
27. Drag and Drop
Drag-and-drop is one of the most common reasons for using the Actions class.
WebElement source = driver.findElement(
By.id("source")
);
WebElement target = driver.findElement(
By.id("target")
);
actions
.dragAndDrop(source, target)
.perform();
28. Drag and Drop Flow
Locate Source
|
v
Click and Hold
|
v
Move to Target
|
v
Release
|
v
Validate Target State
29. dragAndDropBy()
dragAndDropBy() drags an element by a specified X and Y offset.
actions
.dragAndDropBy(source, 150, 0)
.perform();
This is useful when the destination is defined by a position rather than another WebElement.
30. Drag and Drop Using clickAndHold()
When the convenience drag-and-drop method does not work reliably for a custom component, the interaction can be constructed manually.
actions
.clickAndHold(source)
.moveToElement(target)
.release()
.perform();
31. Dragging to an Offset
actions
.clickAndHold(source)
.moveByOffset(200, 0)
.release()
.perform();
32. Slider Automation Using Actions
Sliders can be automated using mouse drag operations.
WebElement slider = driver.findElement(
By.id("priceSlider")
);
actions
.clickAndHold(slider)
.moveByOffset(100, 0)
.release()
.perform();
33. Keyboard Actions
The Actions class can simulate keyboard interactions and can combine keyboard input with pointer operations.
actions
.sendKeys(Keys.ENTER)
.perform();
34. Sending Keys to an Element
actions
.sendKeys(input, "Selenium")
.perform();
The Actions API is particularly useful when keyboard operations need to be combined with other interactions.
35. keyDown()
keyDown() presses and holds a keyboard key until it is released.
actions
.keyDown(Keys.SHIFT)
.perform();
When a modifier key is pressed, it should normally be released using keyUp() after the required interaction.
36. keyUp()
keyUp() releases a key that was previously held.
actions
.keyDown(Keys.SHIFT)
.keyUp(Keys.SHIFT)
.perform();
37. SHIFT + Click
Modifier keys can be combined with mouse actions.
actions
.keyDown(Keys.SHIFT)
.click(element)
.keyUp(Keys.SHIFT)
.perform();
38. CTRL + Click
actions
.keyDown(Keys.CONTROL)
.click(element)
.keyUp(Keys.CONTROL)
.perform();
This can be useful when selecting multiple items in interfaces that support Ctrl-click.
39. CTRL + A
actions
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();
40. CTRL + C
actions
.keyDown(Keys.CONTROL)
.sendKeys("c")
.keyUp(Keys.CONTROL)
.perform();
41. CTRL + V
actions
.keyDown(Keys.CONTROL)
.sendKeys("v")
.keyUp(Keys.CONTROL)
.perform();
42. ALT Key
actions
.keyDown(Keys.ALT)
.sendKeys(Keys.ARROWDOWN)
.keyUp(Keys.ALT)
.perform();
43. ENTER Key
actions
.sendKeys(Keys.ENTER)
.perform();
44. ESCAPE Key
actions
.sendKeys(Keys.ESC)
.perform();
This can be useful for closing menus, dialogs, overlays, and other components that respond to the Escape key.
45. TAB Key
actions
.sendKeys(Keys.TAB)
.perform();
46. Keyboard and Mouse Combination
One of the major advantages of the Actions class is the ability to combine multiple interaction types into a single sequence.
actions
.moveToElement(element)
.click()
.keyDown(Keys.SHIFT)
.sendKeys("hello")
.keyUp(Keys.SHIFT)
.perform();
47. Scrolling Using Actions
Selenium's Actions API also supports wheel-based scrolling.
actions
.scrollByAmount(0, 500)
.perform();
48. Scrolling Horizontally
actions
.scrollByAmount(500, 0)
.perform();
49. Scroll to an Element
WebElement footer = driver.findElement(
By.id("footer")
);
actions
.scrollToElement(footer)
.perform();
This is useful when the target element is outside the current viewport.
50. Scroll Before Clicking
actions
.scrollToElement(button)
.click(button)
.perform();
51. pause()
The pause() method inserts a pause into an Actions sequence.
actions
.moveToElement(menu)
.pause(Duration.ofSeconds(1))
.click(subMenu)
.perform();
For application-state synchronization, explicit waits are generally preferable to arbitrary pauses.
52. Chaining Multiple Actions
Multiple actions can be chained together.
actions
.moveToElement(menu)
.click()
.doubleClick(element)
.perform();
53. Action Sequence Example
actions
.moveToElement(loginMenu)
.click()
.sendKeys(username)
.sendKeys(Keys.TAB)
.sendKeys(password)
.sendKeys(Keys.ENTER)
.perform();
54. Action Builder Pattern
The Actions class follows a builder-style API. Each method can add an interaction to the current action sequence.
Actions actions = new Actions(driver);
actions
.moveToElement(element)
.click()
.sendKeys("Selenium")
.perform();
55. build()
The build() method can be used to create an Action sequence from the configured interactions.
Action action = actions
.moveToElement(element)
.click()
.build();
action.perform();
For most everyday Selenium automation, calling perform() directly is simpler.
56. Action vs Actions
| Action | Actions |
| Represents a configured interaction sequence. | Builder used to create user interaction sequences. |
| Can be executed with perform(). | Provides methods such as click(), moveToElement(), keyDown(), etc. |
| Useful when storing a built sequence. | Commonly used for constructing interactions. |
57. Pointer Input
The Actions API supports pointer input for mouse and other pointer-style interactions at the WebDriver interaction level.
58. Keyboard Input
Keyboard interactions can be constructed using the Actions API.
actions
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.perform();
59. Wheel Input
Wheel input is useful for browser scrolling and is part of Selenium's modern Actions API.
actions
.scrollByAmount(0, 600)
.perform();
60. Action Sequence Concept
At a lower level, Selenium represents interactions as sequences associated with input devices. This allows keyboard, pointer, and wheel interactions to be coordinated.
Input Source
|
+---- Keyboard
|
+---- Pointer
|
+---- Wheel
|
v
Action Sequence
|
v
perform()
|
v
Browser
61. Hover Menu Practical Example
WebElement menu = driver.findElement(
By.cssSelector(".menu")
);
WebElement submenu = driver.findElement(
By.cssSelector(".submenu-item")
);
Actions actions = new Actions(driver);
actions
.moveToElement(menu)
.pause(Duration.ofMillis(500))
.moveToElement(submenu)
.click()
.perform();
62. Drag and Drop Practical Example
WebElement source = driver.findElement(
By.id("drag-source")
);
WebElement target = driver.findElement(
By.id("drop-target")
);
Actions actions = new Actions(driver);
actions
.clickAndHold(source)
.moveToElement(target)
.release()
.perform();
63. Slider Practical Example
WebElement slider = driver.findElement(
By.id("slider")
);
Actions actions = new Actions(driver);
actions
.clickAndHold(slider)
.moveByOffset(100, 0)
.release()
.perform();
64. Double-Click Practical Example
WebElement item = driver.findElement(
By.id("item")
);
Actions actions = new Actions(driver);
actions
.doubleClick(item)
.perform();
65. Right-Click Practical Example
WebElement item = driver.findElement(
By.id("item")
);
Actions actions = new Actions(driver);
actions
.contextClick(item)
.perform();
66. Keyboard Shortcut Practical Example
WebElement input = driver.findElement(
By.id("search")
);
actions
.click(input)
.keyDown(Keys.CONTROL)
.sendKeys("a")
.keyUp(Keys.CONTROL)
.sendKeys("Selenium")
.perform();
67. Combining Hover and Keyboard
actions
.moveToElement(menu)
.click()
.keyDown(Keys.SHIFT)
.sendKeys("selenium")
.keyUp(Keys.SHIFT)
.perform();
68. Actions Class with Explicit Wait
Before interacting with dynamic elements, it is often useful to wait until the element is ready.
WebDriverWait wait = new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
WebElement menu = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("menu")
)
);
Actions actions = new Actions(driver);
actions
.moveToElement(menu)
.perform();
69. Actions and Dynamic Menus
Dynamic menus may appear only after a hover event. The test should verify that the expected submenu actually becomes visible.
actions
.moveToElement(menu)
.perform();
WebElement submenu = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("submenu")
)
);
Assert.assertTrue(submenu.isDisplayed());
70. Actions and Page Object Model
In a professional Selenium framework, complex interactions should be encapsulated inside Page Object classes.
public class HomePage {
private WebDriver driver;
private Actions actions;
private By productsMenu = By.id("products");
public HomePage(WebDriver driver) {
this.driver = driver;
this.actions = new Actions(driver);
}
public void hoverProductsMenu() {
WebElement menu = driver.findElement(
productsMenu
);
actions
.moveToElement(menu)
.perform();
}
}
71. Reusable Hover Utility
public static void hover(
WebDriver driver,
By locator) {
WebElement element = driver.findElement(locator);
new Actions(driver)
.moveToElement(element)
.perform();
}
72. Reusable Double-Click Utility
public static void doubleClick(
WebDriver driver,
By locator) {
WebElement element = driver.findElement(locator);
new Actions(driver)
.doubleClick(element)
.perform();
}
73. Reusable Right-Click Utility
public static void rightClick(
WebDriver driver,
By locator) {
WebElement element = driver.findElement(locator);
new Actions(driver)
.contextClick(element)
.perform();
}
74. Reusable Drag-and-Drop Utility
public static void dragAndDrop(
WebDriver driver,
By sourceLocator,
By targetLocator) {
WebElement source = driver.findElement(
sourceLocator
);
WebElement target = driver.findElement(
targetLocator
);
new Actions(driver)
.dragAndDrop(source, target)
.perform();
}
75. Complete TestNG Example
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
public class ActionsClassTest {
private WebDriver driver;
private Actions actions;
private WebDriverWait wait;
@BeforeMethod
public void setup() {
driver = new ChromeDriver();
driver.manage().window().maximize();
wait = new WebDriverWait(
driver,
Duration.ofSeconds(10)
);
actions = new Actions(driver);
driver.get("https://example.com");
}
@Test
public void testMouseHover() {
WebElement menu = wait.until(
ExpectedConditions.visibilityOfElementLocated(
By.id("products")
)
);
actions
.moveToElement(menu)
.perform();
Assert.assertTrue(menu.isDisplayed());
}
@AfterMethod
public void tearDown() {
if (driver != null) {
driver.quit();
}
}
}
76. Actions Class with Multiple Interactions
@Test
public void testMultipleActions() {
WebElement menu = driver.findElement(
By.id("menu")
);
WebElement item = driver.findElement(
By.id("item")
);
actions
.moveToElement(menu)
.pause(Duration.ofMillis(500))
.moveToElement(item)
.click()
.perform();
}
77. Actions Class vs WebElement Methods
| WebElement | Actions |
| click() | click() |
| sendKeys() | sendKeys() |
| Usually operates directly on an element | Builds user interaction sequences |
| Suitable for basic interaction | Suitable for complex interaction |
| Limited mouse gestures | Hover, drag, click-and-hold, double-click, right-click, etc. |
| Limited keyboard combinations | Supports keyDown/keyUp sequences |
78. Actions Class vs JavaScriptExecutor
| Actions | JavaScriptExecutor |
| Simulates user interactions | Executes JavaScript in the browser |
| Useful for mouse gestures | Useful for DOM-level operations |
| Supports keyboard input | Does not directly model keyboard input |
| Good for drag-and-drop | Can be used as a workaround for difficult interactions |
| Represents supported user gestures | Can directly manipulate browser-side DOM behavior |
79. Common Problems with Actions Class
- Element is not visible.
- Element is outside the viewport.
- Another element overlaps the target.
- Incorrect offset is used.
- Dynamic content changes after hover.
- Drag-and-drop implementation does not respond as expected.
- Mouse pointer starts from an unexpected location for offset-based operations.
- Action sequence is created but not performed.
- Keyboard modifier is pressed but not released.
80. ElementClickInterceptedException
This exception can occur when another element receives the click instead of the intended target.
Possible solutions:
- Wait for overlays to disappear.
- Scroll the element into view.
- Move to the correct element before clicking.
- Check for popups or sticky headers.
- Verify that the target is actually clickable.
81. MoveTargetOutOfBoundsException
This exception can occur when an action attempts to move to an invalid position outside the available browser area.
For offset-based actions, use carefully calculated offsets and make sure the element is available in the viewport.
82. Handling Overlapping Elements
WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(
By.id("button")
)
);
actions
.moveToElement(element)
.click()
.perform();
83. Scrolling Before an Action
WebElement element = driver.findElement(
By.id("target")
);
actions
.scrollToElement(element)
.click(element)
.perform();
84. Modifier Key Mistake
A common mistake is pressing a modifier key without releasing it.
Incorrect:
actions
.keyDown(Keys.CONTROL)
.click(element)
.perform();
Better:
actions
.keyDown(Keys.CONTROL)
.click(element)
.keyUp(Keys.CONTROL)
.perform();
85. Offset-Based Interaction Problems
Hard-coded offsets may behave differently across different screen sizes, browser dimensions, zoom levels, and responsive layouts.
actions
.moveByOffset(500, 0)
.click()
.perform();
This may work in one environment but fail in another. Prefer element-relative interactions whenever possible.
86. Best Practices
- Use stable locators.
- Prefer element-based interactions over hard-coded coordinates.
- Use explicit waits for dynamic elements.
- Release modifier keys after using
keyDown().
- Call
perform() after constructing the interaction sequence.
- Use Page Object Model for reusable interactions.
- Avoid unnecessary JavaScript when a normal Actions interaction works.
- Use
scrollToElement() when the target is outside the viewport.
- Validate the result of every important interaction.
- Keep complex interaction utilities reusable.
- Avoid excessive use of arbitrary pauses.
- Use offsets only when they are genuinely required.
87. Actions Class Automation Flow
Identify Interactive Element
|
v
Determine Interaction Type
|
+-------------------------+
| | |
v v v
Mouse Keyboard Wheel
| | |
+------------+------------+
|
v
Build Action Chain
|
v
perform()
|
v
Browser Interaction
|
v
Validate
88. Real-World Example: E-Commerce Website
An e-commerce application may use several Actions class interactions:
- Hover over product categories.
- Move to a submenu.
- Drag price sliders.
- Double-click editable product elements.
- Scroll through product lists.
- Use keyboard shortcuts in search or filter components.
- Interact with custom shopping interfaces.
89. Real-World Example: File Management Application
A file-management application may require a combination of mouse and keyboard actions.
Open Folder
|
v
Right Click File
|
v
Open Context Menu
|
v
Move to Rename
|
v
Click Rename
|
v
Enter New Name
|
v
Press Enter
90. Real-World Example: Kanban Board
Kanban applications are ideal examples for drag-and-drop automation.
Task Card
|
| Drag
v
In Progress Column
|
v
Release
|
v
Verify Task Position
actions
.clickAndHold(task)
.moveToElement(inProgressColumn)
.release()
.perform();
91. Real-World Example: Multi-Select UI
Actions can be used with modifier keys to select multiple items.
actions
.click(item1)
.keyDown(Keys.CONTROL)
.click(item2)
.click(item3)
.keyUp(Keys.CONTROL)
.perform();
92. Actions Class Interview Questions
Q1. What is the Actions class in Selenium?
The Actions class is a Selenium API used to perform complex mouse, keyboard, and wheel interactions such as hover, drag-and-drop, double-click, right-click, keyboard combinations, and scrolling.
Q2. Which package contains the Actions class?
org.openqa.selenium.interactions.Actions
Q3. How do you create an Actions object?
Actions actions = new Actions(driver);
Q4. Why is perform() used?
perform() executes the action sequence constructed using the Actions API.
Q5. How do you perform mouse hover?
actions.moveToElement(element).perform();
Q6. How do you perform double-click?
actions.doubleClick(element).perform();
Q7. How do you perform right-click?
actions.contextClick(element).perform();
Q8. How do you perform drag-and-drop?
actions
.dragAndDrop(source, target)
.perform();
Q9. What is the difference between dragAndDrop() and dragAndDropBy()?
dragAndDrop() moves an element to another WebElement, whereas dragAndDropBy() moves an element using specified X and Y offsets.
Q10. What is clickAndHold()?
It presses the mouse button and keeps it held until a later release action.
Q11. What is keyDown()?
keyDown() presses and holds a keyboard key so subsequent interactions can use it as a modifier.
Q12. What is keyUp()?
keyUp() releases a previously held keyboard key.
Q13. Can Actions class perform scrolling?
Yes. Selenium's Actions API provides wheel-based scrolling methods such as scrollByAmount() and scrollToElement().
Q14. How do you automate a slider using Actions?
actions
.clickAndHold(slider)
.moveByOffset(100, 0)
.release()
.perform();
Q15. What is the difference between Actions and WebElement?
WebElement methods are primarily designed for direct element interaction, while Actions is designed to build complex interaction sequences involving pointer, keyboard, and wheel inputs.
93. Quick Revision
- Actions is used for advanced Selenium interactions.
- Import it from
org.openqa.selenium.interactions.Actions.
- Create it using
new Actions(driver).
- Use
moveToElement() for hover.
- Use
doubleClick() for double-click.
- Use
contextClick() for right-click.
- Use
clickAndHold() and release() for drag operations.
- Use
dragAndDrop() for element-to-element dragging.
- Use
dragAndDropBy() for offset-based dragging.
- Use
moveByOffset() for relative mouse movement.
- Use
keyDown() and keyUp() for modifier keys.
- Use
sendKeys() for keyboard input.
- Use
scrollByAmount() and scrollToElement() for scrolling.
- Use
perform() to execute the action sequence.
- Use Page Object Model to keep complex interactions reusable.
94. Actions Class Checklist
| Task | Method |
| Simple mouse click | click() |
| Double click | doubleClick() |
| Right click | contextClick() |
| Mouse hover | moveToElement() |
| Mouse movement | moveByOffset() |
| Press and hold | clickAndHold() |
| Release mouse | release() |
| Drag to element | dragAndDrop() |
| Drag by offset | dragAndDropBy() |
| Hold keyboard key | keyDown() |
| Release keyboard key | keyUp() |
| Keyboard input | sendKeys() |
| Vertical/horizontal scroll | scrollByAmount() |
| Scroll to element | scrollToElement() |
| Delay inside action sequence | pause() |
| Execute sequence | perform() |
95. Final Conclusion
The Selenium Actions class is an essential part of advanced WebDriver automation. It enables testers to automate complex user interactions that cannot always be handled effectively with basic WebElement methods.
Using Actions, Selenium automation scripts can perform mouse hover, click-and-hold, drag-and-drop, double-click, right-click, slider movement, keyboard combinations, scrolling, and chained interaction sequences.
For professional automation frameworks, Actions operations should be combined with reliable locators, explicit waits, Page Object Model, reusable utility methods, and proper validations. This makes complex interactions more stable, maintainable, and reusable across Selenium test cases.
96. Selenium Learning Resource
For learning Selenium WebDriver, Java automation, TestNG, Page Object Model, advanced browser interactions, real-time projects, and automation framework concepts, explore the Selenium Training Course.
For course enquiries and demo registration, visit Register for Course Demo.