Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run ScanHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › browser automation

How to Move the Mouse to an Element or Coordinate With Puppeteer

By Freedom251 Team · · 4 min read

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

To hover a DOM element, use await page.locator(selector).hover(). To move the pointer to a specific viewport point, use await page.mouse.move(x, y). Puppeteer’s locator action handles element readiness; coordinate movement gives you low-level control over the destination.

Hover over an element

For an element identified by a selector, use a locator:

As an Amazon Associate I earn from qualifying purchases.

await page.locator('button').hover();

Puppeteer recommends locators for selecting and interacting with elements. Locator hover brings the element into the viewport as needed, waits for it to be visible, and waits for its bounding box to remain stable across two consecutive animation frames before acting. Locator actions can retry when a target is not ready. See the Puppeteer page interactions guide.

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

This is usually the simplest choice for hover menus, tooltips, and other interactions where the target is a particular element rather than a particular screen position.

Use page.hover() as a shortcut

You can also hover using the page-level method:

await page.hover('button');

It scrolls the matching element into view if needed and moves to its center. If multiple elements match, it uses the first; if none match, the call rejects. Use a selector specific enough to identify the intended target. See the Page.hover() API reference.

Move the mouse to a coordinate

For a point rather than an element, call page.mouse.move():

await page.mouse.move(250, 120);

The first number is the horizontal x coordinate and the second is the vertical y coordinate. Puppeteer measures both in main-frame CSS pixels from the viewport’s top-left corner—not from the full page’s top-left. See the Mouse.move() API reference.

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

You can request intermediate pointer movements with the steps option:

await page.mouse.move(250, 120, { steps: 10 });

steps controls the number of movements from the current position to the destination and defaults to 1. This can matter when a page responds to the pointer’s path rather than only its final position. Puppeteer dispatches synthetic mouse events; they do not reproduce every property of a physical mouse. See the Mouse class documentation.

Move to a point inside an element

If you need coordinates derived from an element, get its bounding box, check that it exists, and calculate a point within it. This example moves to the center:

const element = await page.$('button');
if (!element) {
  throw new Error('Button was not found');
}

const box = await element.boundingBox();
if (!box) {
  throw new Error('Element has no layout box');
}

await page.mouse.move(
  box.x + box.width / 2,
  box.y + box.height / 2,
);

boundingBox() returns null if the element is not part of layout, such as when it has display: none. Bounding-box coordinates are relative to the main frame. See the ElementHandle.boundingBox() API reference. If all you need is to hover the element, locator hover avoids manually calculating the point.

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

Choose the right method

Need Use What Puppeteer handles
Hover a selected element page.locator(selector).hover() Viewport presence, visibility, and stable bounding box checks
Hover the first match for a selector page.hover(selector) Scrolls into view and targets the element’s center; rejects if there is no match
Move to a known point page.mouse.move(x, y) Moves to the supplied main-frame viewport coordinates
Move to a point calculated from an element boundingBox() followed by page.mouse.move() You check for a missing element or layout box and calculate the point

Troubleshoot pointer movement

  • The element selector matches nothing: Check the selector and whether the element exists at the time of the call. page.hover() rejects when there is no match; use an appropriately specific selector.
  • The locator cannot hover the target: Confirm the element is visible and can enter the viewport. Locator hover performs readiness checks, so an element that remains hidden or unstable may not be ready to interact with.
  • boundingBox() returns null: The element may not participate in layout—for example, it may use display: none. Make it render before requesting its box, or use another target.
  • The pointer reaches the wrong place: Check coordinate order (x, then y) and remember that coordinates are CSS pixels relative to the viewport’s top-left. For an element center, add half its width to box.x and half its height to box.y.
  • A hover interaction behaves differently from a real user’s: Puppeteer sends synthetic mouse events, which do not fully replicate physical mouse input. A page that depends on hardware-specific behavior may not respond identically.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Capture a page without setting up Puppeteer

Or skip the browser setup

If your goal is a screenshot rather than pointer interaction, ScreenshotNeo can return a page capture with one GET request. It accepts cookie or consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response identifies the page verdict and billing status in its headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.

Example cURL request (replace the URL with the page you want):

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

See the ScreenshotNeo documentation for the API options. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free.

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.

browser automationJavaScriptPuppeteerWeb development

Leave a Reply

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

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

Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

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.