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

To capture a mouse interaction in Selenium, first perform the pointer action with the Actions API, then take a screenshot while the resulting page state is still visible. Use a screenshot of the current browsing context when surrounding page context matters, or an element screenshot when you need only one element. Selenium documents these as separate APIs; there is no special-purpose command that automatically records a mouse interaction.

What Selenium captures—and what it does not

Selenium’s Actions API provides virtualized keyboard, pointer, and wheel input. Its mouse actions include moving to an element or coordinate, clicking, clicking and holding, right-clicking, double-clicking, and dragging and dropping. The screenshot API captures the current browsing context or an individual element. The screenshot endpoint returns Base64-encoded image data. The documentation does not promise that the mouse cursor itself will appear in every browser and driver configuration, so verify cursor rendering in your setup if the pointer graphic must be visible.

As Selenium’s Actions API documentation puts it, the interface is “A low-level interface for providing virtualized device input actions to the web browser.” The examples below use Python consistently.

Capture a hover or other pointer interaction in Python

1. Set up the driver and locate the target

Install Selenium for Python with pip install selenium, and ensure a compatible browser is installed. Selenium Manager can generally obtain the driver when you create a driver instance. This example opens a page, finds a target by CSS selector, and moves the pointer over it.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Elebase USB to USB C Adapter for iPhone 18 Pro Max,USBC Car Charger Adapter
  • Read Before You Buy — No Video Output: These adapters support charging and USB 2.0 data transfer, but cannot transmit video signals. Except for standard USB webcams (which use USB data only), they are not compatible with HDMI/DisplayPort cables, video-capable USB-C hubs, or docking stations with video output.
  • Convert USB-A Ports to USB-C: Designed to connect USB-C earphones, cables, flash drives, card readers, and other USB-C accessories to standard USB-A ports. Plug-and-play with no drivers or software required.
  • Aluminum Alloy Housing: Built with a sturdy aluminum alloy shell that aids in heat dissipation and protects against daily wear and scratches. Designed to maintain a stable and secure connection.
  • Compact & Travel-Friendly: The ultra-compact design allows the adapter to stay plugged into your device without blocking adjacent ports or adding bulk, reducing wear and tear on your original USB ports.
  • 12-Month Warranty: Backed by a 12-month manufacturer warranty for peace of mind. Designed to meet strict quality control standards for reliable everyday performance.
from pathlib import Path

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait

output = Path("hover.png")
driver = webdriver.Chrome()

try:
    driver.get("https://example.com")
    wait = WebDriverWait(driver, 10)

    target = wait.until(
        EC.presence_of_element_located((By.CSS_SELECTOR, "YOUR_SELECTOR"))
    )

    # Hover over the target. This performs the pointer action.
    ActionChains(driver).move_to_element(target).perform()

    # If the hover reveals content, wait for that content to appear.
    # Replace the selector with the revealed element, or remove this wait
    # if the hover state is immediately visible and stable.
    wait.until(
        EC.visibility_of_element_located((By.CSS_SELECTOR, "REVEALED_SELECTOR"))
    )

    # Capture the visible page state after the interaction.
    driver.save_screenshot(str(output))
finally:
    driver.quit()

Replace both placeholder selectors with selectors from the page. If hovering does not reveal a separate element, remove the second wait and capture after the relevant visual change is present. Selenium’s documentation does not prescribe a universal delay: the important condition is that the state you want remains present when the screenshot is taken.

2. Choose the interaction and capture scope

For other common mouse actions, replace the hover call with the corresponding Python ActionChains methods. Keep the screenshot after the action so it captures the resulting state.

Rank #2
Anker USB-C Hub, 5-in-1 USB Hub for Laptops, 4K HDMI Multiport Adapter
  • 5-in-1 USB-C Hub: Experience comprehensive connectivity featuring a Power Delivery input, two USB-A 2.0 ports, a USB-A 3.0 port, and an HDMI port. (Note: The USB-C power delivery input port is only for connecting an external wall charger to power your laptop and cannot power peripheral devices.)
  • 90W Pass-Through Charging: Achieve optimal charging with 90W pass-through power to your laptop, supported by a total input of 100W, with the hub reserving 10W for operational efficiency. (Note: Wall charger not included.)
  • Quick Data Transfers: Accelerate your productivity with rapid data transfers using a high-speed 5Gbps USB 3.0 port and two 480Mbps USB 2.0 ports.
  • 4K HDMI Display: Enhance your visual experience with a hub capable of delivering 4K resolution at 30Hz in both mirror and extend modes. Please note that this hub is compatible with MacBook (macOS 12 and newer), Windows 10 and 11, ChromeOS, and laptops equipped with DP Alt Mode and Power Delivery. Note: This device is not compatible with Linux.
  • What You Get: Anker USB-C Hub (5-in-1, 4K HDMI), welcome guide, 18-month warranty, and our friendly customer service.
# Click an element
ActionChains(driver).click(target).perform()

# Right-click an element
ActionChains(driver).context_click(target).perform()

# Double-click an element
ActionChains(driver).double_click(target).perform()

# Click and hold, move to another element, then release (drag and drop)
source = driver.find_element(By.CSS_SELECTOR, "SOURCE_SELECTOR")
destination = driver.find_element(By.CSS_SELECTOR, "DESTINATION_SELECTOR")
ActionChains(driver).drag_and_drop(source, destination).perform()

driver.save_screenshot("interaction.png")

These snippets are alternatives, not a sequence to run one after another: select the action that matches the behavior under test. For element movement or more involved sequences, the Python mouse guide documents move_to_element, move_by_offset, click_and_hold, release, and other Actions methods. The pointer-movement guide notes that an element used as a movement target must be in the viewport, and that scrolling does not itself change the pointer position. See Selenium’s mouse actions guide.

Use driver.save_screenshot("page.png") to save the current browsing context, which preserves page surroundings. To capture a particular element instead, call its screenshot method:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Anker USB C Hub, 7in1 Multi-Port USB Adapter, 4K@60Hz USBC to HDMI Splitter
  • Sleek 7-in-1 USB-C Hub: Features an HDMI port, two USB-A 3.0 ports, and a USB-C data port, each providing 5Gbps transfer speeds. It also includes a USB-C PD input port for charging up to 100W and dual SD and TF card slots, all in a compact design.
  • Flawless 4K@60Hz Video with HDMI: Delivers exceptional clarity and smoothness with its 4K@60Hz HDMI port, making it ideal for high-definition presentations and entertainment. (Note: Only the HDMI port supports video projection; the USB-C port is for data transfer only.)
  • Double Up on Efficiency: The two USB-A 3.0 ports and a USB-C port support a fast 5Gbps data rate, significantly boosting your transfer speeds and improving productivity.
  • Fast and Reliable 85W Charging: Offers high-capacity, speedy charging for laptops up to 85W, so you spend less time tethered to an outlet and more time being productive.
  • What You Get: Anker USB-C Hub (7-in-1), welcome guide, 18-month warranty, and our friendly customer service.
target.screenshot("element.png")

An element image is limited to that element; do not assume it includes a cursor located elsewhere on the page. Selenium’s window and tab documentation describes both current-context and element screenshots.

Timing and interaction details that affect the result

  • Capture after the visual state appears. A hover may reveal a menu, tooltip, or other transient content. Wait for a meaningful condition, such as visibility of the revealed element, rather than relying on an arbitrary delay when a condition is available.
  • Keep the target in view for pointer movement. Selenium’s mouse guide says the element used for pointer movement must be in the viewport. If necessary, scroll it into view and locate it again before moving the pointer.
  • Account for scrolling. The pointer position does not change when the page is scrolled. After scrolling, issue a new movement to the intended target rather than assuming the pointer followed the page.
  • Check for overlays. Element interactions scroll an out-of-viewport element into view and check interactability. A click can be intercepted if another element obscures the target’s center. See Selenium’s element interaction documentation.
  • Coordinate multiple input devices deliberately. When using low-level action building blocks across multiple input devices, Selenium makes synchronization the caller’s responsibility. Convenience methods cover many common actions; avoid combining unsynchronized device sequences when order matters. See the Actions API documentation.

Troubleshoot screenshots that miss the interaction

Symptom Likely cause What to do
Hover menu or tooltip is missing The screenshot was taken before the state appeared, the pointer missed its target, or the state disappeared before capture. Wait for a visible state-specific element; confirm the target selector and viewport position; perform the screenshot immediately after the state is established.
Pointer movement is rejected or seems to target the wrong place after scrolling The target may not be in the viewport, or scrolling moved the page without moving the pointer. Bring the target into view, then issue a fresh move_to_element call before capture.
Click reports interception or the wrong item is clicked An overlay or another element covers the target’s center, or the page has not reached the expected state. Wait for the obstructing layer to disappear or handle it as the page requires; verify the target is interactable before clicking.
The saved image has no visible cursor Cursor rendering is not guaranteed by the reviewed Selenium screenshot documentation and may depend on browser or driver configuration. Do not treat cursor visibility as guaranteed. If the pointer graphic is essential, verify the output in your exact browser and driver configuration and consider an application-level visual indicator.
Element screenshot omits useful surroundings The selected-element screenshot captures the element rather than the full browsing context. Use driver.save_screenshot when the surrounding page state is important.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If you need a website image rather than a Selenium-driven mouse sequence, ScreenshotNeo can return a screenshot or PDF from one GET request. It is not a replacement for Selenium when you need to move or click the pointer as part of an automated interaction.

Rank #4
Sale
UGREEN USB to USB C Adapter Combo 4-Pack, 10Gbps USB C Converter Space Gray
  • Dual Converters, Infinite Potential:Includes 2× USB C male to USB A female adapters and 2× USB A male to USB C female adapters. Perfect for a wide range of uses—tablets with Bluetooth keyboards, expand USB ports on macbook, and more. Two different converters for all your daily needs
  • Next-Level 10Gbps & 3A Charging: No more slow 480Mbps, this usb to usb c adapter has a transfer speed of up to 10Gbps, allowing you to do more transferring in less time. This usb adapter fits both USB A and USB C charger, supporting up to 3A fast charging
  • Upgraded Exquisite Craftsmanship: With an aluminum alloy housing and metal connector, the usbc to usb adapter is extremely durable and sturdy. Rigorously tested to withstand more than 10,000 times of plugging and unplugging, ensuring long-lasting performance
  • Broad Compatible: The usb c to usb adapter widely supports all USB C/ USB A devices like laptops, tablets, cellphones, car chargers, and phone chargers. Such as compatible with MacBook Pro/Air 2023/2022, Thunderbolt 4/3 Devices,Apple MagSafe Watch 9/8/7/SE/Ultra, iPad Pro 2022/2021, Samsung Galaxy S23/S20/S10, and iPhone 17/16/15 Pro. Plug and play
  • Please Note: To reach 10Gbps speed, keep the cable under 3.3 ft. For USB A Male to USB C adapters, try flipping the USB C connector. USB C Male to USB A adapters support bidirectional 10Gbps transfer within 3.3 ft

Its API accepts and removes cookie/consent banners, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks/CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers indicate the page verdict and billing status. ScreenshotNeo also offers an MCP server for AI agents, with tools including take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots.

For API options and setup, see the ScreenshotNeo documentation. Example cURL request:

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

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

Best Value
Anker USB C Hub, 5-in-1 USBC to HDMI Splitter with 4K Display
  • 5-in-1 Connectivity: Equipped with a 4K HDMI port, a 5 Gbps USB-C data port, two 5 Gbps USB-A ports, and a USB C 100W PD-IN port. Note: The USB C 100W PD-IN port supports only charging and does not support data transfer devices such as headphones or speakers.
  • Powerful Pass-Through Charging: Supports up to 85W pass-through charging so you can power up your laptop while you use the hub. Note: Pass-through charging requires a charger (not included). Note: To achieve full power for iPad, we recommend using a 45W wall charger.
  • Transfer Files in Seconds: Move files to and from your laptop at speeds of up to 5 Gbps via the USB-C and USB-A data ports. Note: The USB C 5Gbps Data port does not support video output.
  • HD Display: Connect to the HDMI port to stream or mirror content to an external monitor in resolutions of up to 4K@30Hz. Note: The USB-C ports do not support video output.
  • What You Get: Anker 332 USB-C Hub (5-in-1), welcome guide, our worry-free 18-month warranty, and friendly customer service.

Frequently Asked Questions

Does taking a screenshot move or click the mouse in Selenium?

No. Perform the pointer action with the Actions API first, then call the screenshot API.

Can I guarantee the cursor will appear in a Selenium screenshot?

No cursor-visibility guarantee is established by Selenium’s reviewed screenshot documentation; check the output in your browser and driver configuration.

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.

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