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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

To capture a mouseover state in Selenium, move the pointer to the target with the Actions API, wait for the hover UI to render, then save the current window. The target must be in the viewport. In Python, the dependable pattern is ActionChains(driver).move_to_element(target).pause(0.5).perform() followed by driver.save_screenshot(...).

The reliable hover-to-screenshot workflow

A screenshot records the browser exactly as it is when the command runs. Selenium does not infer that you want a tooltip, menu, or highlight; you must create that state with a pointer action first.

  1. Open the page and locate the element that responds to mouseover.
  2. Scroll it into the viewport if necessary.
  3. Move the virtual pointer with ActionChains.
  4. Pause long enough for CSS transitions or JavaScript to finish.
  5. Save the window screenshot and verify that the save call succeeded.

Selenium’s mouse-actions documentation describes move_to_element as moving to the element’s in-view center. It also notes that an element must be in the viewport or the command errors.

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

Complete Python example

Install Selenium, make a WebDriver available (for example, ChromeDriver for Chrome), and adjust the URL and selector to your page. The deterministic artifact name makes failures easy to inspect in CI.

#1 Best Overall
Sale
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")
options.add_argument("--window-size=1440,1000")
driver = webdriver.Chrome(options=options)

try:
    driver.get("https://example.com/products")

    hover_target = driver.find_element(
        By.CSS_SELECTOR, "[data-testid='menu']"
    )

    # The target has to be visible to Selenium's mouse action.
    driver.execute_script(
        "arguments[0].scrollIntoView({block: 'center', inline: 'nearest'});",
        hover_target,
    )

    ActionChains(driver) 
        .move_to_element(hover_target) 
        .pause(0.5) 
        .perform()

    output = Path("artifacts/menu-hover.png")
    output.parent.mkdir(parents=True, exist_ok=True)
    saved = driver.save_screenshot(str(output))
    if not saved:
        raise IOError(f"WebDriver could not save {output}")
finally:
    driver.quit()

save_screenshot writes a PNG of the current browser window. The Python Chromium WebDriver API returns True when the save succeeds and False for an I/O error, so check the return value instead of assuming an artifact exists.

Why screenshots miss the hover state

The element is outside the viewport

A locator can find an element that is below or beside the visible area. Scroll it into view before the action. If a sticky header overlaps the target, center it and then confirm the actual hit area is unobstructed.

The screenshot runs too soon

Menus and tooltips often appear after a timer, a transition, or a network-backed update. Add a pause in the same action chain rather than taking an immediate screenshot. Start with a short value such as 0.5 seconds and increase it only when the page demonstrably needs more time.

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

The pointer is over the wrong part

move_to_element uses the in-view center. That is correct for most cards and menu items, but a trigger may be a small icon, a corner, or a child region. Use a deliberate offset when the center is not the real hotspot:

target = driver.find_element(By.CSS_SELECTOR, "[data-testid='help-icon']")
driver.execute_script("arguments[0].scrollIntoView({block: 'center'});", target)
ActionChains(driver) 
    .move_to_element_with_offset(target, 8, -6) 
    .pause(0.5) 
    .perform()
driver.save_screenshot("artifacts/help-hover.png")

Offsets are relative to the element’s in-view center. Keep them stable and choose them from the page’s actual hit area; arbitrary offsets make a test fragile when the layout changes.

The hover target disappears or is replaced

Responsive layouts and reactive menus can replace a node after scrolling. Locate the element as close as possible to the action, and do not retain a stale reference across a page update. If the page changes after the move, locate the visible trigger again and repeat the action.

Rank #2
Sale
Logitech G305 Lightspeed Wireless Gaming Mouse - Black
  • The next-generation optical HERO sensor delivers incredible performance and up to 10x the power efficiency over previous generations, with 400 IPS precision and up to 12,000 DPI sensitivity
  • Ultra-fast LIGHTSPEED wireless technology gives you a lag-free gaming experience, delivering incredible responsiveness and reliability with 1 ms report rate for competition-level performance
  • G305 wireless mouse boasts an incredible 250 hours of continuous gameplay on just 1 AA battery; switch to Endurance mode via Logitech G HUB software and extend battery life up to 9 months
  • Wireless does not have to mean heavy, G305 lightweight mouse provides high maneuverability coming in at only 3.4 oz thanks to efficient lightweight mechanical design and ultra-efficient battery usage
  • The durable, compact design with built-in nano receiver storage makes G305 not just a great portable desktop mouse, but also a great laptop travel companion, use with a gaming laptop and play anywhere

Center hover versus offset hover

Choice Pointer location Use it when Main risk
Center In-view center of the element The whole element is the trigger A narrow child hotspot may not receive the event
Offset Coordinates relative to the in-view center Only a specific icon, edge, or child region triggers the UI Layout changes can invalidate the coordinates

When diagnosing a missing state, capture both variants temporarily. If the offset works but the center does not, the selector probably identifies a container rather than the actual hover region.

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

Choosing the right synchronization

Fixed pause

pause(seconds) is simple and works well for a known CSS transition. Keep the delay in the action chain so the pointer remains over the element while the browser waits.

ActionChains(driver).move_to_element(target).pause(1).perform()

State-aware wait

For a tooltip or dropdown with a predictable selector, wait for the resulting element before saving. This avoids guessing a large delay and makes the failure meaningful:

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

ActionChains(driver).move_to_element(target).perform()
WebDriverWait(driver, 10).until(
    EC.visibility_of_element_located((By.CSS_SELECTOR, "[role='tooltip']"))
)
driver.save_screenshot("artifacts/tooltip.png")

The pause pattern is still useful when the transition has no convenient DOM condition. Selenium’s Actions API documents chaining a move, pause, click-and-hold, another pause, and keystrokes; the same pause mechanism applies before a screenshot.

Full-window and element screenshots

driver.save_screenshot captures the current window, including the hover UI wherever it appears. That is usually the right choice for a menu or tooltip whose position matters in context.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Logitech M185 Compact Ambidextrous Wireless Mouse with Rubber Grips - Blue
  • Compact Mouse: With a comfortable and contoured shape, this Logitech ambidextrous wireless mouse feels great in either right or left hand and is far superior to a touchpad
  • Durable and Reliable: This USB wireless mouse features a line-by-line scroll wheel, up to 1 year of battery life (2) thanks to a smart sleep mode function, and comes with the included AA battery
  • Universal Compatibility: Your Logitech mouse works with your Windows PC, Mac, or laptop, so no matter what type of computer you own today or buy tomorrow your mouse will be compatible
  • Plug and Play Simplicity: Just plug in the tiny nano USB receiver and start working in seconds with a strong, reliable connection to your wireless computer mouse up to 33 feet / 10 m (5)
  • Better than touchpad: Get more done by adding M185 to your laptop; according to a recent study, laptop users who chose this mouse over a touchpad were 50% more productive (3) and worked 30% faster (4)

Some Selenium bindings also support an element-level screenshot. Use it when you need only the hovered card or component and the hover decoration is contained inside that element. Compare both scopes while debugging: an element capture can hide an overlay rendered elsewhere in the document.

# Full browser window
driver.save_screenshot("artifacts/window-hover.png")

# Element-level capture where supported by your binding
card = driver.find_element(By.CSS_SELECTOR, "[data-testid='product-card']")
card.screenshot("artifacts/card-hover.png")

Debugging checklist

  • Print or inspect the target’s bounding rectangle and confirm it intersects the viewport.
  • Try the center first, then a documented offset within the real trigger region.
  • Take one screenshot immediately and one after a pause to prove whether timing is the issue.
  • Use a visible-state wait when the tooltip or menu has a stable selector.
  • Use a fixed viewport and deterministic output path in automated runs.
  • Open the saved PNG as a CI artifact; a successful WebDriver call does not prove that the intended UI appeared.

Common errors and fixes

“Move target out of bounds” or an equivalent viewport error

Cause: the element is not in the viewport. Fix: scroll it into view, account for sticky overlays, and retry the action.

The screenshot is valid but the tooltip is absent

Cause: the capture happened before the hover delay, or the pointer landed on a non-triggering region. Fix: add an action-chain pause, wait for the tooltip’s visibility, and test an offset.

StaleElementReferenceException

Cause: the framework replaced the node after a scroll or render. Fix: locate the target again immediately before moving the pointer.

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.

The file is missing

Cause: the destination directory does not exist or the process lacks write access. Fix: create the directory, use an absolute or known working path, and assert the Boolean returned by save_screenshot.

Headless and headed results differ

Cause: different viewport dimensions or responsive breakpoints. Fix: set the same window size explicitly and verify that the target remains visible at that size.

Rank #4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
  • Computer mouse for easily navigating a computer interface; click, scroll, and more
  • USB-A wired connection; if existing device only supports USB-C, an additional adapter will be required
  • High-definition (1000 dpi) optical tracking ensures responsive cursor control for precise tracking and easy text selection
  • 3 buttons offer effortless fingertip control
  • Plug-and-go ready for instant use

Performance, reliability, and test design

Hover screenshots add browser work: locating, scrolling, pointer dispatch, rendering, and image encoding. Keep selectors specific, avoid unnecessary long pauses, and capture only the states that matter. A short, state-aware wait is generally more reliable than a large fixed sleep.

Give each state its own filename, such as nav-products-hover.png and help-tooltip-hover.png. This prevents later captures from overwriting evidence and lets a failed run show exactly which state was missing. For visual regression tests, hold the viewport, browser theme, and page data constant; otherwise a valid hover action can still produce a different image.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo provides a website screenshot API when you need a rendered page image without maintaining Selenium and a browser. It can accept consent banners before capture and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and the response identifies the page verdict and billing status in X-Page-Verdict and X-Billed headers. Its MCP server exposes take_screenshot, get_page_info, and capture_pdf to Claude, Cursor, and other MCP clients.

For a one-call capture, see the ScreenshotNeo documentation:

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

The API also supports full-page captures with lazy images loaded, CSS-selector element captures, dark mode, device presets and custom viewports, retina scale, PDF controls, custom CSS and JavaScript, pre-capture clicks, hidden selectors, waits for a selector, delay or network idle, request and resource blocking, headers, cookies, user agents, Authorization, timezone, geolocation, transparent backgrounds, resizing, chosen cache TTLs, signed image links, asynchronous jobs with signed webhooks, bulk capture of up to 100 URLs per call, a usage API, and an OpenAPI specification. Common parameter names used by other screenshot APIs are accepted to ease migration.

Plan Included shots Price
Free 1,000 per month No card
Starter 3,000 $5
Growth 15,000 $15
Pro 60,000 $39
Scale 250,000 $99
Business 1,000,000 $249

Yearly billing gives two months free, and every feature is included on every plan. Start with 1,000 free screenshots a month—no card required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Sale
Acer Wireless Mouse for Laptop, 2.4GHz Computer Mouse 3 Adjustable 1600 DPI
  • 【Plug and Play for Home/Office/School】The wireless computer mouse features 2.4GHz connectivity, delivering a stable, interference-free connection up to 32ft. Designed for 𝐦𝐞𝐝𝐢𝐮𝐦 𝐭𝐨 𝐥𝐚𝐫𝐠𝐞 𝐬𝐢𝐳𝐞𝐝 𝐡𝐚𝐧𝐝𝐬, it ensures comfortable use all day. Simply plug in the USB-A receiver for instant pairing—no drivers needed. 📌📌 If the mouse isn’t suitable, place the USB receiver in the battery compartment and return both.
  • 【3 Levels Adjustable DPI】This travel USB mouse offers 3 adjustable DPI settings (800, 1200, 1600), allowing you to customize sensitivity for precise design work. Effortlessly switch to match your task and elevate your productivity. 📌 Please remove the film at the bottom of the mouse before use.
  • 【Effortless Browsing】Equipped with forward and backward buttons, this computer mice streamlines your workflow, making it easy to navigate through web pages and files with a simple click. 📌Side button does not work on Mac.
  • 【Visible Indicator Light】 The pc mouse features a visual indicator for DPI levels and low battery alerts. The red light flashes once for 800 DPI, twice for 1200 DPI, and three times for 1600 DPI. When the battery level is below 10%, the light flashes red until the mouse is completely out of power.
  • 【Click to Wake】With smart sleep mode, it saves power by standby after 10 inactive minutes, just 2-3 clicks to wake. This efficient design delivers 3x longer battery life than motion-wake mice. Engineered for durability, its buttons and scroll wheel are tested for 10 million clicks, ensuring long-term reliability and consistent performance.

FAQ

Can I hover over a hidden element with Selenium?

No. The documented mouse move requires an in-viewport target. Make the element visible and unobstructed first.

What pause should I use?

There is no universal value. Match the page’s transition or wait for a specific visible result when one exists.

Why use an offset instead of changing the selector?

An offset is useful when the same DOM element contains a narrow, position-specific hotspot that has no separate selectable node.

Does a successful save prove the hover worked?

No. It proves that a PNG was written. Inspect the artifact or assert the tooltip/menu state separately.

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

Frequently Asked Questions

Can I hover over a hidden element with Selenium?

No. The documented mouse move requires an in-viewport target. Make the element visible and unobstructed first.

What pause should I use?

There is no universal value. Match the page’s transition or wait for a specific visible result when one exists.

Why use an offset instead of changing the selector?

An offset is useful when the same DOM element contains a narrow, position-specific hotspot that has no separate selectable node.

Does a successful save prove the hover worked?

No. It proves that a PNG was written. Inspect the artifact or assert the tooltip/menu state separately.

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.

Quick Recap

SaleBestseller No. 1
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Logitech M185 Compact Ambidextrous 2.4 GHz Wireless Mouse - Swift Grey
Product carbon footprint: 3.97 kg CO2e; Contoured shape: Gives you more comfort and control
$14.90
SaleBestseller No. 3
Bestseller No. 4
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Amazon Basics 3-Button USB Wired Mouse with Responsive Tracking, Plug & Play, Compatible with Windows and Mac, Black
Computer mouse for easily navigating a computer interface; click, scroll, and more; 3 buttons offer effortless fingertip control
$9.70

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.