Actions Class in Selenium

Reviewed by The Kiran Academy technical training team · Updated 13 September 2026 · Selenium 4 / Java

What is the Actions class in Selenium?

org.openqa.selenium.interactions.Actions is Selenium's builder for complex mouse and keyboard interactions, including hover, right-click, double-click, drag-and-drop and key combinations.
Correct nameActions is plural; Action represents a built sequence.
Essential stepCall perform(), or build and then perform the action.
Use it forComposite interactions beyond basic WebElement methods.
Stability tipWait until the target is interactable before starting.
WebElement menu = driver.findElement(By.id("products"));
new Actions(driver)
    .moveToElement(menu)
    .click()
    .perform();
Common mistakes: forgetting perform(), using fixed sleeps, and mixing examples from different Selenium language bindings.

Choose the right Selenium interaction

TaskRecommended APIWhy
Normal click or typingWebElement.click() / sendKeys()Simplest high-level interaction
Hover, right-click, double-clickActionsModels a pointer sequence
Keyboard shortcutkeyDown(), sendKeys(), keyUp()Keeps modifier state explicit
Wheel scrollingActions wheel inputSupported by Selenium 4's W3C Actions API

Execution model: chained calls describe a sequence. perform() sends that sequence to the browser. Use build() when you need to store the resulting Action and run it later.

Frequently asked questions

What is the difference between Action and Actions?

Actions is the builder used to compose input steps. Action represents a built sequence that can be performed.

Why does moveToElement fail?

The element may be hidden, covered, stale or outside a ready layout. Wait for visibility and interactability, then locate it as close as possible to the action.

Does Actions support scrolling?

Yes. Selenium 4 includes wheel input actions, including scrolling by an amount, from an origin or to an element.

Primary reference: Selenium documentation — Actions API.

The Selenium Actions class builds composite keyboard, pointer and wheel input sequences. Use it for hover, double-click, right-click, drag-and-drop and keyboard shortcuts.

The Java class is org.openqa.selenium.interactions.Actions. The table below introduces common operations; verify exact signatures against the current Selenium Java API.



Method Name Description
addAction Adds an action to current list of actions to be performed.
build Builds the sequence of actions.
click() Clicks the mouse at the last known mouse coordinates.
click(IWebElement) Clicks the mouse on the specified element.
clickAndHold() Clicks and holds the mouse button at the last known mouse coordinates.
clickAndHold(IWebElement) Clicks and holds the mouse button down on the specified element.
contextClick() Right-clicks the mouse at the last known mouse coordinates.
contextClick(IWebElement) Right-clicks the mouse on the specified element.
doubleClick() Double-clicks the mouse at the last known mouse coordinates.
doubleClick(IWebElement) Double-clicks the mouse on the specified element.
dragAndDrop Performs a drag-and-drop operation from one element to another.
dragAndDropToOffset Performs a drag-and-drop operation on one element to a specified offset.
equals Determines whether the specified Object is equal to the current Object.(Inherited from Object.)
finalize Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.(Inherited from Object.)
getHashCode Serves as a hash function for a particular type. (Inherited from Object.)
getLocatableFromElement Gets the ILocatable instance of the specified IWebElement. Gets the Type of the current instance.
getType (Inherited from Object.)
keyDown(String) Sends a modifier key down message to the browser.
keyDown(IWebElement, String) Sends a modifier key down message to the specified element in the browser.
keyUp(String) Sends a modifier key up message to the browser.
keyUp(IWebElement, String) Sends a modifier up down message to the specified element in the browser.
memberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
moveByOffset Moves the mouse to the specified offset of the last known mouse coordinates.
moveToElement(IWebElement) Moves the mouse to the specified element.
moveToElement(WebElement, Int32, Int32) Moves the mouse to the specified offset of the top-left corner of the specified element.
perform Performs the currently built action.
release() Releases the mouse button at the last known mouse coordinates.
release(IWebElement) Releases the mouse button on the specified element.
sendKeys(String) Sends a sequence of keystrokes to the browser.
sendKeys (IWebElement,String) Sends a sequence of keystrokes to the specified element in the browser.
to String Returns a String that represents the current Object. (Inherited from Object.)

Step 1: Import the Actions and Action classes

    import org.openqa.selenium.interactions.Action;
    import org.openqa.selenium.interactions.Actions;

Step 2: Instantiate a new Actions object.

    Actions builder = new Actions(driver);

Step 3: Instantiate an Action using the Actions object in step 2.

    Action mouseOverHome = builder.moveToElement(link_Home).build();

In this case, we are going to use the moveToElement() method because we are simply going to mouse-over the "Home" link. The build () method is always the final method used so that all the listed actions will be compiled into a single step.

Step 4: Use perform() method when executing the Action object we designed in Step 3.

    mouseOverHome.perform();

You can build a series of multiple actions using the Action and Actions classes. Just remember to close the series with the build () method.


action class example




Ready for structured training?

Learn Software Testing with real projects

Live classes, practical projects, interview preparation and placement support in one guided programme.

View Software Testing Course Book Free Demo