Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
browser automation

How to Take a Screenshot of a Specific Element with Puppeteer

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

Use ElementHandle.screenshot() to capture one DOM element instead of the whole page. In a Node.js script, wait for a stable selector, get the element handle, then save the screenshot. Puppeteer scrolls the element into view if needed; if the page replaces the element during rendering, acquire a fresh handle before capturing.

Capture an element with Puppeteer

This complete Node.js example opens a page, waits for a visible element identified by a data attribute, saves it as a PNG, and closes the browser even if navigation or capture fails. Install Puppeteer in your project first with npm install puppeteer, then save this as element-shot.mjs and run it with node element-shot.mjs.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();

try {
  const page = await browser.newPage();
  await page.goto('https://example.com', { waitUntil: 'networkidle2' });

  const element = await page.waitForSelector('[data-testid="profile-card"]', {
    visible: true,
    timeout: 30_000,
  });

  if (!element) {
    throw new Error('Profile card was not found');
  }

  await element.screenshot({ path: 'profile-card.png', type: 'png' });
  await element.dispose();
} finally {
  await browser.close();
}

Replace the example URL and selector with the page and element you need. Puppeteer’s screenshot guide demonstrates this same core pattern: obtain an element with waitForSelector, then call ElementHandle.screenshot(). The API reference says the element method scrolls the target into view when needed, then uses the page screenshot machinery to capture it.

Choose a selector that identifies the right element

The selector determines which node gets captured. Prefer a stable identifier the site controls, such as an id, a test attribute, or a component-specific attribute. CSS selectors are Puppeteer’s default, so an element with id="summary" can be selected with #summary, while a test attribute can be selected as [data-testid="profile-card"].

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.
#1 Best Overall
Sale
Philips 24 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 241V8LB
  • CRISP CLARITY: This 23.8″ Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors
  • WORK SEAMLESSLY: This sleek monitor is virtually bezel-free on three sides, so the screen looks even bigger for the viewer. This minimalistic design also allows for seamless multi-monitor setups that enhance your workflow and boost productivity
  • A BETTER READING EXPERIENCE: For busy office workers, EasyRead mode provides a more paper-like experience for when viewing lengthy documents

Use an id or data attribute

const element = await page.waitForSelector('#summary', { visible: true });
if (!element) throw new Error('Summary was not found');
await element.screenshot({ path: 'summary.png' });

Data attributes are often useful in automation because they can remain stable while classes and visual styling change. Avoid selecting an incidental class if the application routinely renames generated classes.

Use other selector types when CSS is not enough

Puppeteer also supports text, XPath, ARIA accessible-name selectors, open shadow-DOM combinators, and custom query handlers. For example, an accessibility selector can identify a button by its accessible name and role:

const button = page.locator('::-p-aria([name="Download report"][role="button"])');
await button.screenshot({ path: 'download-button.png' });

Locators are Puppeteer’s recommended abstraction for selecting an element and interacting with it. They provide automatic waiting around supported actions. Use a locator when the operation you need is available in your installed Puppeteer version and its waiting behavior suits the page. If your version’s locator API does not expose the screenshot operation you need, use waitForSelector and an ElementHandle, as in the main example.

Rank #2
Philips 22 Inch Computer Monitor FHD 100Hz VA VESA Flicker-Free, 221V8LB
  • CRISP CLARITY: This 22 inch class (21.5″ viewable) Philips V line monitor delivers crisp Full HD 1920x1080 visuals. Enjoy movies, shows and videos with remarkable detail
  • 100HZ FAST REFRESH RATE: 100Hz brings your favorite movies and video games to life. Stream, binge, and play effortlessly
  • SMOOTH ACTION WITH ADAPTIVE-SYNC: Adaptive-Sync technology ensures fluid action sequences and rapid response time. Every frame will be rendered smoothly with crystal clarity and without stutter
  • INCREDIBLE CONTRAST: The VA panel produces brighter whites and deeper blacks. You get true-to-life images and more gradients with 16.7 million colors
  • THE PERFECT VIEW: The 178/178 degree extra wide viewing angle prevents the shifting of colors when viewed from an offset angle, so you always get consistent colors

Wait until the target is ready

page.waitForSelector(selector) resolves when the selector appears. Set visible: true when the target must both exist and be visible before capture. The documented default timeout is 30,000 milliseconds; set timeout to another number of milliseconds to change it, or use timeout: 0 to disable the timeout.

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

Visibility is not the same as application readiness. A visible card may still contain placeholder text, an image may still be loading, or a framework may replace the node after hydration. If the screenshot needs a particular final state, wait for a condition that represents that state before acquiring the handle. For example, wait for the final text or a page-specific ready attribute, then locate the element you intend to capture. Do not keep a handle obtained before a re-render and assume it still points to the live node.

For pages with continuous network activity, choosing a navigation wait condition is a trade-off: waiting for networkidle2 can be useful for pages that settle quickly, but it can delay or time out on sites that keep requests open. Where that happens, use a navigation condition appropriate to the page and wait explicitly for the target’s readiness rather than relying on network silence alone.

Rank #3
Sale
Dell 24 Monitor - SE2426H - 23.8-inch FHD (1920x1080) 144Hz 1ms Display, in-Plane Switching (IPS) Technology, AMD FreeSync™, TÜV 3-Star 2X HDMI, Tilt
  • Clear visuals. Fluid motion: A 144Hz refresh rate and 1ms MPRT deliver smooth, tear‑free motion across work, gaming, and streaming for clearer, more fluid viewing.
  • Eye comfort: TÜV Rheinland 3‑star* certification reduces harmful blue light while preserving stunning color quality without compromise. *TÜV Rheinland 3-star eye comfort certification.
  • Wide viewing angle: Get consistent views across a wide 178° /178° viewing angle.
  • In-Plane Switching (IPS): See excellent color accuracy and consistency across wide viewing angles with In-plane Switching (IPS) technology.
  • Ultra-thin bezels: Maximize your viewing experience with thin bezels.

Set the screenshot format and output

ElementHandle.screenshot() accepts screenshot options. Set path to write a file; omit it when you want the returned screenshot data in your program. Set type explicitly when you need a particular format or when the filename extension alone is not enough to communicate the desired output.

Option Use Important detail
path Save the output to a file, such as card.png. Omit it to receive binary image data instead.
type Choose a screenshot format such as PNG, JPEG, or WebP. Check the supported format values in the ScreenshotOptions reference for your installed version.
quality Set image quality for formats that support a quality setting. It does not apply to PNG.
omitBackground Use true when you need a transparent background. Useful for image formats and output workflows that support transparency.
fullPage Capture the whole page rather than only the viewport. This is generally a page-level concern; an element handle already scopes the capture to that element.
clip and captureBeyondViewport Control a screenshot region and viewport behavior where supported. They affect capture geometry; consult the version’s options reference before combining them with an element capture.

For example, a transparent PNG can be requested with await element.screenshot({ path: 'card.png', type: 'png', omitBackground: true });. Use an explicit format and filename that agree, then verify the resulting file with the software that will consume it.

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

Get the element screenshot without managing Puppeteer

If your goal is to obtain a website capture rather than run a browser in your own environment, ScreenshotNeo provides a screenshot API and MCP server. For a one-request capture, use cURL as shown below. See the ScreenshotNeo documentation for API details.

Rank #4
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor
  • CURVED FOR ENHANCED ENGAGEMENT: An immersive viewing experience with a curved monitor that wraps more closely around your field of vision; It creates a wider view, enhancing depth perception and minimizing peripheral distraction
  • SMOOTH PERFORMANCE FOR SEAMLESS CONTENT: Stay in the action when playing games, watching videos, or working on creative projects; The 100Hz refresh rate reduces lag and motion blur so you don't miss a thing in fast-paced moments¹
  • MORE GAMING POWER: Gain the edge with optimizable game settings; Color and image contrast can be adjusted to see scenes more vividly and spot enemies hiding in the dark; Game Mode adjusts any game to fill the screen so you can view every detail²
  • KEEP IT EASY ON THE EYES: Care for your eyes and stay comfortable, even during long sessions; Advanced eye comfort technology certified by TÜV reduces eye strain by minimizing blue light and reducing irritating screen flicker²
  • INCREASED VERSATILITY: Connect to more; Plug devices straight into your monitor for increased flexibility, making your computing environment even more convenient
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

This captures the page URL; it is not a Puppeteer CSS-selector element capture. ScreenshotNeo removes cookie and consent banners from more than 60 known consent platforms, along with newsletter popups and chat widgets, before the capture; each of those cleanup steps can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and the response indicates 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 for Claude, Cursor, and other MCP clients. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo and start with 1,000 free screenshots a month, no card required.

Fix blank, clipped, or stale element captures

The selector times out or finds nothing

  • Cause: The selector does not match the live page, or the page has not reached the state in which the element appears.
  • Fix: Check the selector against the rendered DOM, use a stable id or data attribute, and wait for the page-specific condition that makes the element available. Increase the timeout only when the page legitimately needs more time; an unlimited wait can leave an automation run stuck.

The element handle is detached

  • Cause: The page replaced or removed the node after Puppeteer obtained its handle. Puppeteer documents a detached-element error for this case.
  • Fix: Wait for the re-render or final readiness condition, then query the selector again and screenshot the newly acquired handle. Do not reuse a handle from before the replacement.

The screenshot is blank or shows placeholder content

  • Cause: The target may exist before its real content is ready, or it may be hidden while the page is in a transition.
  • Fix: Require visibility when appropriate and wait for a content-specific readiness signal. A selector appearing only proves that a matching element exists; it does not prove that every image, font, or asynchronous update in the component has finished.

The capture is clipped or has unexpected dimensions

  • Cause: The element’s rendered bounds, viewport behavior, or screenshot-region options do not match the output you expected.
  • Fix: Inspect the element’s on-page dimensions and the viewport used for the page, then review clip and captureBeyondViewport behavior for your Puppeteer version. Use an element screenshot for one node; fullPage is ordinarily a page-capture setting, not a way to enlarge a single element capture.

The output format or transparency is wrong

  • Cause: The selected format and extension disagree, a quality option is being applied to PNG, or the target format does not preserve the background behavior you need.
  • Fix: Set type explicitly, use quality only with supported formats, and request omitBackground: true when transparency is wanted and supported by the output format.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Performance and reliability considerations

A single element screenshot still requires loading and rendering its page: the method narrows the captured region, but it does not avoid navigation, JavaScript execution, or the target page’s network and rendering work. Reuse a browser process for a sequence of captures when appropriate rather than repeatedly paying browser startup cost, and make sure every page and browser is closed on success and failure. Set timeouts deliberately so a stalled page does not hold a job indefinitely.

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

For repeatable output, control the page state before capture: use a consistent viewport, wait for the target content, and avoid acquiring the element handle until the page has finished replacing that node. When processing many URLs or running in constrained infrastructure, account for the memory and time used by each browser page and bound concurrent work to what the environment can support. Puppeteer’s screenshot options and selector API can vary with releases; official Puppeteer pages displayed version 25.12.0 where shown in the documentation used for this guide, so verify the current API reference against the version installed in your project.

Best Value
Sale
Sceptre New 22-Inch Gaming Monitor, FHD 1080p, Up to 144Hz, HDMI, DisplayPort, Built-in Speakers, Machine Black (E225W-FW144 Series, 2026)
  • 【INTEGRATED SPEAKERS】Whether you're at work or in the midst of an intense gaming session, our built-in speakers provide rich and seamless audio, all while keeping your desk clutter-free.
  • 【EASY ON THE EYES】 Protect your eyes and enhance your comfort with Blue-Light Shift technology. This feature reduces harmful blue light emissions from your screen, helping to alleviate eye strain during long hours of use and promoting healthier viewing habits.
  • 【WIDEN YOUR PERSPECTIVE】Our sleek minimal bezel design ensures undivided attention. The nearly bezel-free display seamlessly connects in a dual monitor arrangement, delivering an unobstructed view that lets you focus on more at once, completely distraction-free.

Quick decision guide

  • Use ElementHandle.screenshot() when you need a screenshot of one matched DOM element.
  • Use waitForSelector when you need explicit presence and visibility conditions or a handle-based screenshot workflow.
  • Use a locator when its supported operation and automatic waiting fit your task.
  • Use page screenshot options for output format, file path, transparency, or page-level capture behavior.
  • Reacquire a handle after hydration or a re-render if the original node may have been detached.

Frequently Asked Questions

Can a Puppeteer element screenshot include content that extends below the browser viewport?

The element screenshot method scrolls the element into view before capturing it. For behavior beyond the viewport or custom capture regions, check the captureBeyondViewport and clip options supported by your installed Puppeteer version.

Can Puppeteer select an element inside a shadow root?

Puppeteer supports open shadow-DOM selector combinators. The documented selector support here is for open shadow DOM; do not assume an inaccessible closed shadow root can be queried the same way.

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.

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.

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.

Read next

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.