October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk6 min

What Is the Actions Class in Selenium? How to Use It

Selenium’s Actions API composes low-level keyboard, pointer, and wheel gestures. Learn the Java pattern, common interactions, viewport requirements, and troubleshooting.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Selenium’s Actions API lets you build low-level keyboard, pointer, and (in supported browsers) wheel-input sequences, then send them to the browser. Use it when a test needs a gesture such as hovering, dragging, holding a key while typing, or scrolling by a defined amount. In Java, create an Actions object with the WebDriver, chain the operations, and call perform().

What is the Actions class in Selenium?

The Actions API is Selenium WebDriver’s “low-level interface for providing virtualized device input actions to the web browser.” It models keyboard input, pointer input—such as mouse, pen, or touch—and wheel input as sequences that you can compose and execute.

As an Amazon Associate I earn from qualifying purchases.

It is useful when the test needs to represent a device gesture rather than simply invoke an element-level operation. For a routine button press or text entry, ordinary element interactions are often simpler. For a hover menu, a keyboard chord, a click-and-drag, or a carefully timed sequence, Actions offers more control. The exact method names and signatures vary by language binding; the examples below use Java unless stated otherwise.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How do I use Actions in Selenium?

Find the element, create an Actions instance from the active WebDriver, chain actions, and execute them with perform(). This Java pattern illustrates a press-and-hold on an element:

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;

WebElement target = driver.findElement(By.id("target"));
new Actions(driver)
    .moveToElement(target)
    .clickAndHold()
    .perform();

This leaves the pointer button held; add a release when the gesture is complete. The driver retains input state between sequences, so creating a new Actions object does not by itself release a button or key already pressed.

Equivalent concepts in other bindings

  • Python: the comparable API is commonly exposed as ActionChains.
  • JavaScript: use driver.actions(); the JavaScript API reference describes synchronized ticks for coordinated inputs.
  • .NET: use the binding’s own Actions types and casing.

Consult the reference for the binding and Selenium version in your project before adapting a Java example. Selenium’s Actions API guide documents the shared concepts and language-specific patterns.

Which interactions can Actions perform?

Hover over an element

Move the pointer to an element’s in-view center. This is useful for hover menus or controls that appear only when the pointer is over a region.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
new Actions(driver)
    .moveToElement(driver.findElement(By.id("menu")))
    .perform();

Element-based pointer movement requires the target to be in the viewport. See Selenium’s mouse actions guide for pointer behavior and examples.

Click, double-click, or open a context menu

Actions includes pointer operations such as click, double-click, and context-click. Use these where the test specifically needs the corresponding pointer gesture; for a straightforward click, an element’s ordinary click() is usually the more direct choice.

Hold and drag

For a drag gesture, press on the source, move to the destination, and release. Selenium also provides a drag-and-drop convenience method.

WebElement source = driver.findElement(By.id("source"));
WebElement destination = driver.findElement(By.id("destination"));
new Actions(driver)
    .clickAndHold(source)
    .moveToElement(destination)
    .release()
    .perform();

Whether a page responds to a simulated drag depends on the page’s interaction behavior as well as the target positions. Keep the release in the sequence so the pointer button is not left pressed.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Enter a keyboard chord

Use key-down and key-up operations to hold a modifier while entering a character or text. For example, the sequence can press Shift, type a character, and release Shift:

new Actions(driver)
    .keyDown(Keys.SHIFT)
    .sendKeys("a")
    .keyUp(Keys.SHIFT)
    .perform();

Import org.openqa.selenium.Keys for this Java example. Selenium’s keyboard actions guide covers key-down, key-up, and text entry. For ordinary form entry, element-level sendKeys() may be simpler.

Scroll with wheel input

Selenium documents wheel actions for scrolling by horizontal or vertical deltas and for scrolling toward an element. Wheel input was introduced in Selenium 4.2, but the wheel guide labels the documented actions Chromium-only; verify support for the exact browser and Selenium binding you use.

Actions does not automatically bring a target into view before pointer interaction. If an element is below the viewport, explicitly scroll it into view or use a documented wheel action, then perform the pointer interaction. Review the current scroll wheel actions guide for the available methods and browser limitation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Insert a pause

A pause can be chained when a gesture requires a deliberate interval. Prefer waiting for a page condition when the goal is to synchronize with loading or a UI state; a fixed pause only waits for the stated duration and does not establish that the page is ready.

How are compound actions timed?

Actions can combine input sources, such as a pointer and keyboard, in coordinated sequences. In the JavaScript reference, synchronized ticks are the default; in asynchronous sequences, the caller must add pauses as needed to coordinate devices. That timing detail is specifically documented for JavaScript, so check the equivalent behavior of your binding rather than assuming every language implements asynchronous sequences identically.

Use the JavaScript Actions API reference for its tick and synchronization details.

Viewport, browser, and input-state constraints

  • Keep pointer targets in view. Pointer movement to an element and offset movement have viewport constraints. Scroll before interacting when necessary.
  • Check wheel compatibility. Selenium’s documented wheel actions are labeled Chromium-only; do not assume identical support in other browsers.
  • Release what you press. Keys and pointer buttons can remain active after a sequence. Include key-up or release operations as appropriate, or use the binding-specific reset or release guidance in the Actions guide.
  • Choose the right interaction level. Actions is not a universal replacement for click() or send_keys(). Use it for low-level device gestures, offsets, or timing that element methods do not express.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting Actions sequences

Pointer movement or click fails because the target is out of view

Scroll the page or use an appropriate wheel action before moving the pointer. Confirm the target is in the viewport at the time the sequence runs; Actions does not automatically scroll it into view.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A button or modifier seems stuck

Make sure every press has a matching release: release() for a pointer button and keyUp() for a held key. If a previous sequence failed partway through, use the reset or release mechanism documented for your language binding.

A wheel action is unsupported

Check the browser and binding. The Selenium wheel guide describes its actions as Chromium-only, and wheel support is version-sensitive. Use a supported browser or a different page-scrolling approach where appropriate.

A combined sequence runs at the wrong time

For a JavaScript asynchronous sequence, add pauses where input sources need coordination, as explained in the JavaScript Actions reference. For page readiness, synchronize on a relevant condition instead of treating a fixed pause as proof that loading has finished.

A simple click or text entry is unnecessarily complicated

Use the element’s standard click() or send_keys() when no device-level gesture is required. Reserve Actions for interactions that need its additional control.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Or skip the browser setup

If the job is to capture a page image or PDF rather than test a browser gesture, ScreenshotNeo is a website screenshot API and MCP server. A GET request returns a PNG, JPEG, WebP, or PDF. The following cURL call captures a page as WebP; see the ScreenshotNeo API documentation for request options.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan to try 1,000 screenshots a month with no card.

Frequently Asked Questions

Does creating a new Actions object release a key or mouse button left down earlier?

No. The WebDriver retains input state across sequences; explicitly release or reset inputs using the guidance for your binding.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Can Selenium wheel actions scroll in every browser?

The Selenium wheel guide labels its documented actions Chromium-only. Check the current guide and your browser-binding combination.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.