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 desk4 min

Screenshot a Specific Element by CSS Selector

Use Playwright or Puppeteer to capture the rendered region of a CSS-selected element, with practical guidance for selectors, page state, and common capture problems.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To screenshot one element selected by CSS, locate it in your browser automation script and call the element’s screenshot method. In Playwright, use page.locator('.target').screenshot({ path: 'element.png' }); in Puppeteer, select the element and call its screenshot() method. The image is clipped to the element’s rendered region, not the whole page.

Capture an element with Playwright

Playwright’s page.locator() accepts CSS selectors. Call screenshot() on the locator to save an image of the matched element:

const target = page.locator('.target');
await target.screenshot({ path: 'element.png' });

For example, with a page already open in a Playwright script:

await page.goto('https://example.com');
await page.locator('.target').screenshot({ path: 'element.png' });

Replace .target with a selector for the element you want. The screenshot is clipped to that element’s position and dimensions. See the Playwright locator screenshot documentation for the API details.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Choose a selector that identifies the intended element

If a selector matches repeated components, make sure you are capturing the right one. For example, a page may contain several .card elements. Refine the selector or choose the intended match explicitly. A locator is useful when the page may re-render: Playwright documents that a locator can resolve the matching element again after DOM changes, unlike a handle tied to a particular element. See Playwright locators.

Capture an element with Puppeteer

In Puppeteer, select the element and call screenshot() on its ElementHandle:

const element = await page.$('.target');
if (!element) {
  throw new Error('No element matched .target');
}
await element.screenshot({ path: 'element.png' });

The explicit missing-element check prevents the script from proceeding as if a capture succeeded when the selector matched nothing. Puppeteer’s element screenshot method scrolls the element into view if needed, then captures it using the page screenshot machinery. See the Puppeteer screenshot guide.

Make the capture reflect the state you need

A selector identifies a DOM element; it does not guarantee that the page has finished rendering the content you want. Navigate, wait for the target or relevant content to appear, and capture only when the page is in the intended state. There is no universal readiness condition for every site, so choose a condition appropriate to the page and workflow.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
  • Confirm the match. If the page has repeated elements, verify your selector targets the intended one.
  • Check visibility. A target covered by another element can be obscured in the screenshot. For Playwright, an overlay can hide the target even though the locator matches it.
  • Account for page changes. When the DOM may replace an element during rendering, locator-based targeting in Playwright can re-resolve the match.
  • Check the installed version. API signatures and defaults can vary; consult documentation for the version in your project.

Troubleshoot blank, wrong, or partial captures

Symptom Likely cause What to check
No image or a selector error The selector did not match an element, or the target was not present yet. Check the selector against the current DOM and wait for the target state your page requires.
The wrong repeated component appears The selector matches multiple elements. Refine the selector or explicitly select the intended match.
The image is blank or obscured An overlay or another element covers the target. Inspect the page at capture time and address the covering element if appropriate.
The capture is partial or content is missing The page or target content may not have reached the desired state before capture. Wait for the relevant content or state rather than assuming navigation alone means it is ready.
Element is outside the viewport Capture behavior differs by library. Puppeteer documents scrolling the element into view for its element screenshot method. Check the installed library’s documentation for the workflow you use.

Choose Playwright or Puppeteer based on your workflow

Both libraries document element-level screenshots. Prefer the automation library already used in your project. Playwright offers locator-based targeting that can resolve again after DOM changes; Puppeteer’s documented element screenshot behavior includes scrolling the target into view when needed. The cited API documentation does not establish a speed or image-fidelity winner.

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 can capture a page through one GET request, including an element selected by CSS. Cookie banners are accepted and removed before capture along with 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 response headers identify the page verdict and billing status. Its MCP server provides screenshot tools for AI agents, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000.

For selector options and the API details, see the ScreenshotNeo documentation.

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

Visit ScreenshotNeo for the service details, or sign up free for 1,000 screenshots a month with no card.

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. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.