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

Capture a Website Screenshot Only After a Specific Element Appears in Playwright

Use a retrying visibility assertion or locator wait before capturing a specific element in Playwright, and choose the screenshot scope that matches the image you need.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Wait for the target locator to become visible, then take the screenshot. In Playwright Test, use the retrying toBeVisible() assertion; use locator.waitFor() when you need an explicit state wait. The examples below distinguish an element-only image from a viewport or full-page capture.

Wait for the element, then capture it

For a Playwright Test test, a web-first assertion is usually the clearest choice: it both verifies the visible state and retries until that condition is met or the assertion timeout expires.

As an Amazon Associate I earn from qualifying purchases.

import { test, expect } from '@playwright/test';

test('capture after the panel appears', async ({ page }) => {
  await page.goto('https://example.com');

  const panel = page.getByRole('region', { name: 'Order summary' });
  await expect(panel).toBeVisible();
  await panel.screenshot({ path: 'order-summary.png' });
});

This is an illustrative example; replace the URL and locator with values that match your application. The role and accessible name must identify the intended region. If the element has no suitable role, use a meaningful text or label locator, or a deliberate test ID.

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

Playwright Test’s default timeout for asynchronous expect matchers is 5,000 ms, and it can be configured. See Playwright’s test documentation and check the configuration for your project.

#1 Best Overall
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

Choose a locator that identifies the right element

A locator is a query that Playwright evaluates when it is used, rather than a one-time stored DOM element. Prefer selectors tied to how a user understands the page, such as a role and accessible name, label, or text. Use a test ID when it is an intentional testing contract. Avoid long CSS or XPath chains tied to incidental DOM structure. See the locator guide and Playwright best practices.

Make the locator specific enough to identify one intended target. If multiple elements match, fix the locator rather than silently taking the first match; an ambiguous selector can capture the wrong content.

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

Use an explicit locator wait when that fits better

Outside a web-first assertion, or when the surrounding code calls for a direct state wait, wait on the locator before capturing:

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.
const target = page.getByTestId('report-panel');
await target.waitFor({ state: 'visible', timeout: 10_000 });
await target.screenshot({ path: 'report-panel.png' });

visible is the default state. Other supported states include attached, detached, and hidden. Use attached only when DOM presence is enough; an attached element may not be displayed. Playwright defines visibility as a non-empty bounding box and no visibility: hidden. That check does not guarantee the element is unobscured or visually prominent. Consult the Page API reference and the locator API documentation for the installed Playwright version.

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.

Decide what the screenshot should include

Capture call Image boundary Use it when
await target.screenshot({ path: 'target.png' }) The matched element, clipped to its bounds You need just the target component
await page.screenshot({ path: 'viewport.png' }) The visible viewport by default You need the page as currently framed
await page.screenshot({ path: 'full.png', fullPage: true }) The full scrollable page You need content beyond the current viewport

In the last two cases, keep the same wait and replace the element screenshot with the appropriate page screenshot call. Locator-based element screenshots are the preferred way to capture a matched element. Screenshot options can vary by Playwright release; check the API documentation for your installed version before relying on version-specific options.

For dynamic pages, screenshot options include animation handling and masks for known volatile or sensitive regions. A screenshot used for a visual assertion is a different workflow: toHaveScreenshot() is intended for comparison and waits for consecutive screenshots to stabilize. See the LocatorAssertions documentation.

Rank #4
Sale
Samsung 27" Essential S3 (S36GD) Series FHD 1800R Curved Computer Monitor | 100Hz, Game Mode, Advanced Eye Comfort, HDMI and D-sub Ports (LS27D366GANXZA)
  • 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
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 an image or PDF rather than a Playwright test, ScreenshotNeo can return one from a GET request. For a PNG, JPEG, or WebP response, set the output format as needed; this example saves the response body as WebP. See the ScreenshotNeo API documentation for request options.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo accepts cookie and consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. 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’s free plan.

Troubleshoot missed or incorrect captures

  • The wait times out: Check that navigation reached the expected page and that the locator matches the actual accessible role, name, text, or test ID. Confirm that the element becomes visible before the configured timeout.
  • The element exists but the wait does not pass: DOM attachment is not the same as visibility. If the requirement is appearance, wait for visible, not attached.
  • The screenshot is blank or captures the wrong instance: Make the locator identify the intended element uniquely. If you meant to capture the page rather than the component, use page.screenshot().
  • A fixed delay seems unreliable: waitForTimeout() waits for elapsed time, not the condition you care about. Replace it with the visible assertion or locator wait.
  • An immediate check returns too soon: isVisible() checks immediately and does not wait for a future state. Use expect(target).toBeVisible() in Playwright Test or target.waitFor({ state: 'visible' }).
  • The image differs between runs: Identify dynamic or sensitive regions and consider screenshot masking or animation controls. For regression comparisons, use the screenshot assertion workflow rather than assuming a one-off capture has the same stabilization behavior.

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.