DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk3 min

How to Hover Over an Element with Puppeteer

Use Puppeteer’s Locator API to hover over an element, learn when page.hover() is useful, and handle targets inside frames.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For ordinary interactions, use Puppeteer’s Locator API: await page.locator('button').hover(); Replace 'button' with a selector for the element you want. A Locator hover brings the element into the viewport, waits for it to be visible, and waits for its bounding box to remain stable across two animation frames before hovering.

Use a Locator to hover over an element

In current Puppeteer guidance, a Locator is the recommended starting point for selecting and interacting with an element. This minimal example assumes page is an open Puppeteer Page:

As an Amazon Associate I earn from qualifying purchases.

await page.locator('[data-testid="menu-trigger"]').hover();

Use a selector that identifies the intended target. CSS selectors work by default; Puppeteer also documents selector syntax for text, accessibility role and name, XPath, and queries through open shadow roots.

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.

For a standalone script, the hover action fits after navigation:

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({ headless: true });
  try {
    const page = await browser.newPage();
    await page.goto('https://example.com');
    await page.locator('button').hover();
    // Assert or wait for the hover-triggered state here.
  } finally {
    await browser.close();
  }
})();

Replace the example URL and selector with the page and element under test. Hovering performs the pointer action; in a test, follow it with an assertion or wait for the state your application is expected to show.

Use the page-level shorthand when it suits your code

page.hover(selector) remains documented:

await page.hover('button');

This method scrolls the matching element into view if needed, then moves the mouse to its center. When multiple elements match, it targets the first; when none match, the promise rejects. Prefer a selector that uniquely identifies the target when the page contains repeated buttons or controls.

Choose the right hover method

  • Locator hover: Use page.locator(selector).hover() for ordinary interactions where readiness checks and retries are useful. For hover, the documented checks include viewport placement, visibility, and a stable bounding box.
  • page.hover(): Use the concise page-level selector method when its first-match, center-hover behavior is what you want.
  • Page.mouse: Use the lower-level mouse API when you need to move the pointer without first selecting an element, or need more control over pointer movement.

Hover over an element inside a frame

A page-level selector should not be assumed to reach into a separate frame. Select the relevant frame, then use its hover method or Locator:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const frame = page.frames().find(frame => frame.url().includes('widget'));
if (!frame) {
  throw new Error('Target frame was not found');
}
await frame.locator('button').hover();

Adjust the frame lookup and selector to match the page. The example checks for a frame before interacting so a missing frame produces a clear error rather than an attempt to hover through the main page.

Troubleshoot a hover that does not work

  • No matching element: Check that the selector matches the rendered page and identifies the intended element. With page.hover(), no match rejects; with either method, inspect whether the target is actually in the main page or a frame.
  • The wrong item reacts: The page-level method uses the first match. Narrow the selector, for example by using a test ID or a more specific CSS selector.
  • The menu or tooltip does not appear: Wait for or assert the expected state after hovering. The hover call performs the pointer action; it does not itself verify the application response.
  • The target is inside a frame: Find the relevant frame and call that frame’s Locator or hover method rather than querying only the main page.
  • You need a non-center pointer position or custom movement: Use the page’s mouse API for lower-level pointer control instead of relying on the element-hover shorthand.
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 your goal is a screenshot rather than exercising hover behavior in a browser test, ScreenshotNeo can return a webpage screenshot or PDF from one GET request. It does not perform a Puppeteer hover interaction, so use Puppeteer when the hover state itself is what you need to test.

For example, this cURL request captures a URL as WebP:

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

See the ScreenshotNeo documentation for request options. Cookie and consent banners, newsletter popups, and chat widgets are removed before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status. An 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 screenshots.

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

Sign up free for 1,000 screenshots a month with no card.

Best Value
The SQL Programming Language: .
  • Used Book in Good Condition

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 *

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
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.