Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober 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

Puppeteer: Take a Screenshot of an Element by CSS Selector

Find an element with a CSS selector, then use its Puppeteer element handle to save a screenshot. Includes output options, common failure fixes, and a hosted alternative.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use page.waitForSelector() to find the element, then call screenshot() on the returned element handle. Puppeteer scrolls the element into view if needed.

Capture an element by CSS selector

This runnable example saves the selected element as a PNG:

As an Amazon Associate I earn from qualifying purchases.

const element = await page.waitForSelector('.target');
if (!element) throw new Error('Target element was not found');
await element.screenshot({ path: 'element.png' });

Here, page is an existing Puppeteer Page. Replace .target with a CSS selector that identifies the element you want. The screenshot guide demonstrates this selector-to-element-handle approach: Puppeteer Screenshots guide.

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.

Choose a selector and wait for the right element

Use a selector specific enough to identify the intended element, such as a stable class or ID. waitForSelector() waits for a match; if the target never appears, the wait can fail rather than producing an image of the wrong content. For pages that replace or rerender DOM nodes, make sure the selector resolves to the current element before capturing.

Puppeteer recommends locators for selecting and interacting with elements because they wait for an element to be present and in the right state for an action. The screenshot guide shows the lower-level ElementHandle method used here; use waitForSelector() and an element handle when locator functionality does not meet the need for this capture workflow. See Puppeteer page interactions.

Set output and screenshot options

  • path writes the screenshot to a file; Puppeteer infers the image format from the extension.
  • type lets you specify the image format explicitly.
  • omitBackground can omit the default background for transparency where supported.
  • clip sets a capture region, but for a selected element, ElementHandle.screenshot() already targets that element.
  • fullPage is a page-wide option; it is not needed to capture only the selected element.
  • PNG ignores the quality setting.

For example, to receive bytes instead of writing a file, omit path; ElementHandle.screenshot() returns image bytes by default. Set encoding: 'base64' if you specifically need a base64 string. Check the ScreenshotOptions reference for the supported options.

Or skip the browser setup

For a hosted capture, ScreenshotNeo can return a screenshot with one GET request. It is a screenshot API and MCP server for developers. Its clean-shot steps accept cookie or consent banners like a visitor and remove 60+ known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, with the page verdict and billing status reported in response headers.

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

cURL:

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

Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

See the ScreenshotNeo API documentation for setup and request options. Its MCP server lets AI agents—including Claude, Cursor, and other MCP clients—use take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

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

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Frequently Asked Questions

Does the element screenshot include content outside the element?

No. It captures the selected element, rather than the whole page.

Can I get a base64 result instead of a file?

Yes. Omit path for image bytes, or set encoding: 'base64' for a base64 string.

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

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
Crashes, No Sound, or Screen Glitches?Free driver scan
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.