Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon 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 NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › browser automation

How to Capture a Webpage Screenshot After Waiting for a Selector in Playwright

By Freedom251 Team · · 5 min read

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

Wait for a locator to reach the state your screenshot requires, then capture the page or the element. For example, this waits until .ready is visible before saving the current viewport:

const target = page.locator('.ready');
await target.waitFor({ state: 'visible' });
await page.screenshot({ path: 'page.png' });

Replace .ready with a selector for the page element you need. A visible element is a useful readiness signal when it must appear in the image, but it does not prove that every other part of the page has finished loading.

As an Amazon Associate I earn from qualifying purchases.

Wait for the state that matches your screenshot

Use locator.waitFor() to wait for a specific element state before taking a screenshot. Playwright documents locator waiting and selector states in its Locator API. The state option lets you express whether the element should be attached, visible, hidden, or detached.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const target = page.locator('.ready');
await target.waitFor({ state: 'visible' });
await page.screenshot({ path: 'page.png' });

Choose the state based on what “ready” means for your capture:

#1 Best Overall
Sale
Epson Workforce ES-50 Compact & Lightweight Mobile Document Scanner | For Computers including PC and Mac Receipt and Document Scanner USB Powered
  • PORTABLE SCANNER FOR USE ON-THE-GO — The fastest and lightest mobile single-sheet-fed compact document scanner in its class¹
  • QUICK DOCUMENT SCANNING ― This Epson ultra-fast scanner scans a single page as quickly as 5.5 seconds²; Windows and Mac compatible
  • VERSATILE PAPER HANDLING ― Portable scanner scans documents up to 8.5 x 72 in; Also easily digitizes receipts and ID cards to make accounting, bookkeeping, and organizing simpler
  • INTUITIVE, HIGH-SPEED SOFTWARE — Epson ScanSmart Software³ is a smart tool allowing you to easily scan, review, and save; Stay organized easily with the help of this Epson scanner
  • EASY SETUP — USB-powered connect to your computer for quick and simple scanning; No batteries or external power supply required to operate portable document scanner; Standard Connectivity: USB 2.0
  • visible: use when the element needs to be visible in the screenshot.
  • attached: use when presence in the DOM is enough, even if the element is not visible.
  • hidden or detached: use when the capture should happen after an element becomes hidden or is removed.

Do not treat a wait timeout as permission to capture anyway. A timeout means the requested condition was not met; handle it as a failed readiness check or investigate the page state.

Choose a locator that will survive page changes

Prefer a locator based on user-facing attributes such as a role, accessible name, label, placeholder, alt text, title, or a test ID. CSS and XPath selectors are supported, but selectors tied to long chains of internal markup can break when the page structure changes. See Playwright’s locator guidance.

Rank #2
Sale
Brother DS-640 Compact Mobile Document Scanner, (Model: DS640)
  • FAST SPEEDS - Scans color and black and white documents a blazing speed up to 16ppm (1). Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • ULTRA COMPACT – At less than 1 foot in length and only about 1. 5lbs in weight you can fit this device virtually anywhere (a bag, a purse, even a pocket).
  • READY WHENEVER YOU ARE – The DS-640 mobile scanner is powered via an included micro USB 3. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan.
  • WORKS YOUR WAY – Use the Brother free iPrint&Scan desktop app for scanning to multiple “Scan-to” destinations like PC, Network, cloud services, Email and OCR. (2) Supports Windows, Mac and Linux and TWAIN/WIA for PC/ICA for Mac/SANE drivers. (3)
  • OPTIMIZE IMAGES AND TEXT – Automatic color detection/adjustment, image rotation (PC only), bleed through prevention/background removal, text enhancement, color drop to enhance scans. Software suite includes document management and OCR software. (4)

For example, when the page exposes a button with an accessible name, a role-based locator is usually clearer than a CSS path:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const target = page.getByRole('heading', { name: 'Account overview' });
await target.waitFor({ state: 'visible' });
await page.screenshot({ path: 'account.png' });

Use a CSS selector such as .ready when it is the appropriate stable hook for the page or test. The key is that the selector identifies the element whose state actually signals readiness for your task.

Rank #3
Sale
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
  • STAY ORGANIZED – Easily convert your paper documents into digital formats like searchable PDF files, JPEGs, and more.Power Consumption : 2.5W or less (Energy Saving Mode: 0.7W). Suggested Daily Volume : 500 scans..Does it contain liquid: no
  • CONVENIENT AND PORTABLE –lightweight and small in size, you can take the scanner anywhere from home offices, classrooms, remote offices, and anywhere in between
  • HANDLES VARIOUS MEDIA TYPES – Digitize receipts, business cards, plastic or embossed cards, reports, legal documents, and more
  • FAST AND EFFICIENT – No technical hurdles or complicated setups here; easily scan both sides of a document at the same time, in color or black-and-white, at up to 12 pages-per-minute, and with a 20 sheet automatic feeder
  • BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer

Capture the viewport, full page, element, or buffer

Once the wait has succeeded, choose the screenshot method that matches the output you need. Playwright documents these options in its screenshot API.

Need Code Result
Current viewport await page.screenshot({ path: 'page.png' }); Saves the visible viewport.
Full scrollable page await page.screenshot({ path: 'page.png', fullPage: true }); Saves a full-page image.
Only the target element await target.screenshot({ path: 'element.png' }); Saves an image of the locator’s element.
Image in memory const buffer = await page.screenshot(); Returns screenshot bytes rather than saving directly to a path.

For an element-only image, wait on and capture the same locator:

Rank #4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
  • IRIScan Express, portable scanner : scans color and black and white documents a blazing speed up to 8ppm simplex. Color scanning won’t slow you down as the color scan speed is the same as the black and white scan speed.
  • IRIScan Express mobile scanner is powered via an included micro USB 2. 0 cable allowing you to use it even where there is no outlet available. Plug it into you PC or laptop and you are ready to scan. USB cable provided. AC Adapter not provided and not needed.
  • IRIScan flatbed scanner uses a simplex scanning mode allows for quick and straightforward scanning of single-sided documents. IRIScan with its full portable features is the ideal document scanners for computers.
  • IRIScan document scanner : Versatile scanning capabilities, including scanning to Word, PDF, and Excel formats with companion software provided Readiris OCR
  • Receipt scanner and card scanner with Additional features include scanning business cards directly to Outlook, photo scanning, and receipt scanning for efficient document management
const target = page.locator('.ready');
await target.waitFor({ state: 'visible' });
await target.screenshot({ path: 'element.png' });

Make the readiness check as specific as the page

A selector wait establishes only the condition you asked for. An attached element may still be invisible, and a visible element does not guarantee that unrelated asynchronous content, images, or fonts are ready. If the screenshot depends on more than one thing, wait for the page-specific signals that matter to the image.

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

Avoid adding a fixed sleep as a substitute for a meaningful condition. Explicit locator waits are useful when screenshot timing depends on a particular visible or DOM state; they are more informative than an arbitrary delay. Playwright’s API marks page.waitForSelector() as discouraged and points developers toward locator waits or web-first assertions in its Page API guidance.

Best Value
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
  • Scanner type: Document
  • Connectivity technology: USB
  • With Auto Scan Mode, the scanner automatically detects what you're scanning
  • Digitize documents and images
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use screenshot assertions for visual regression tests

For an image file, use page.screenshot() or locator.screenshot(). For a Playwright Test baseline comparison, use expect(page).toHaveScreenshot() instead. That assertion waits for two consecutive page screenshots to match and compares the resulting capture with the expected snapshot; it is a test-runner workflow, not merely another way to save an image. See the Playwright visual comparisons documentation.

Visual output can differ across operating systems, browser versions, settings, hardware, power sources, and headless mode. Keep the rendering environment consistent between baseline creation and comparison when dependable visual diffs matter, as described in the snapshot guidance.

Troubleshoot missed or incomplete screenshots

  • The wait times out: Check that the selector matches an element and that the chosen state can occur. Do not silently continue with an incomplete capture.
  • The element exists but is not in the image: You may have waited for attached when the element needed to be visible. Wait for visible if visibility is the required condition.
  • The target appears but other content is missing: The target’s state does not establish that unrelated asynchronous content has finished. Add the specific readiness checks needed by the page.
  • The screenshot has the wrong scope: page.screenshot() captures the viewport by default. Set fullPage: true for a full-page image or call target.screenshot() for an element image.
  • A locator stops matching after a page redesign: Replace brittle internal CSS or XPath chains with a stable user-facing locator or test ID where available.
  • A visual test differs across machines: Check for rendering-environment differences and use consistent operating system, browser version, settings, and execution mode for baselines and comparisons.

Or skip the browser setup

If you need a screenshot from a URL without setting up a Playwright browser workflow, ScreenshotNeo is a website screenshot API and MCP server for developers. Its one-request API returns an image or PDF; its capture options include waiting for a selector, a delay, or network idle.

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

See the ScreenshotNeo API documentation for request parameters. Cookie banners are accepted and removed before capture, along with known newsletter popups and chat widgets; each cleanup step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response identifies the page verdict and billing status in headers. An MCP server provides screenshot tools for AI agents, including Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month with no card required; paid plans start at $5 for 3,000 shots.

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

Quick Recap

SaleBestseller No. 3
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
Canon imageFORMULA R10 - Portable Document Scanner, USB Powered, Duplex Scanning, Document Feeder, Easy Setup, Convenient, Perfect for Mobile Users, White
BROAD COMPATIBILITY – Works with both Windows and Mac devices, be it laptop or computer; This product is not intended for scanning photographs on photo paper / photographic media
$153.00
Bestseller No. 4
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
IRIScan Express 4 Black Compact Portable USB Simplex Document Scanner, 8 PPM for Contracts, Invoices and Business Cards, Compatible with Windows, Readiris PDF Included
Find our Software here : irislink.com/start; IRIScan Express is only compatible Windows platform and not macintosh
$129.00
Bestseller No. 5
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Canon Canoscan Lide 300 Scanner (PDF, AUTOSCAN, Copy, Send)
Scanner type: Document; Connectivity technology: USB; With Auto Scan Mode, the scanner automatically detects what you're scanning
$75.00

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.

browser automationJavaScriptPlaywrightvisual testingWebpage screenshots

Leave a Reply

Your email address will not be published. Required fields are marked *

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.

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.