To capture a Playwright screenshot after a cookie consent banner is dismissed, identify the banner’s actual consent control, wait for it to appear, click the appropriate control, and then take the screenshot. There is no universal banner selector or single consent choice that works for every site. The example below uses a placeholder selector: replace it with a locator that matches the page you are testing.
Dismiss the banner through the page’s normal consent control
A cookie banner is usually an HTML element in the page, not a JavaScript browser dialog. Handle it like other page UI: wait for the expected banner or button, interact with the site’s real control, and capture after the banner is gone. Playwright recommends explicitly waiting for a predictable overlay and dismissing it in the normal test flow rather than relying on page.addLocatorHandler() (Playwright Page API).
The example uses Node.js with Playwright. Replace YOUR_BANNER_BUTTON_SELECTOR with a selector for the site’s visible reject, accept, or close control, according to the behavior your test is meant to cover. It deliberately does not assume that accepting optional cookies is the right choice.
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage({ viewport: { width: 1440, height: 900 } });
try {
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
const consentButton = page.locator('YOUR_BANNER_BUTTON_SELECTOR');
await consentButton.waitFor({ state: 'visible', timeout: 10000 });
await consentButton.click();
// Wait for the overlay itself to leave the page before capturing.
await page.locator('YOUR_BANNER_SELECTOR').waitFor({ state: 'hidden', timeout: 10000 });
await page.screenshot({ path: 'page.png' });
} finally {
await browser.close();
}
})();
Use a selector based on the target site’s actual markup or accessible name. For example, when the button has a reliable accessible name, a locator such as page.getByRole('button', { name: 'Reject optional cookies' }) is often clearer than a CSS selector. The banner and button locators may be different: wait for the button to be visible, click it, then wait for the banner container to become hidden or detached.
Free tools Windows power users keep installed
One-click scans. No signup required.
Make the consent choice explicit
- Use the site’s reject control when the test should exercise refusal of optional cookies.
- Use accept only when the test specifically covers that choice.
- If the site provides a close control, use it only when closing the banner is the behavior under test; closing may not record a consent preference.
Handle sites where the banner is conditional
If the banner appears only for a fresh profile, create a fresh browser context for the test. If the test intentionally reuses saved consent, persist and load the context state as part of the test setup. Avoid silently skipping the interaction when the banner is expected: a missing or changed control should fail clearly rather than produce a screenshot whose consent state is unknown.
Choose the screenshot scope and output
Use a regular viewport screenshot when the goal is to record what a visitor sees on screen. Use fullPage: true when the capture should include content below the fold. Playwright’s page.screenshot() also supports image type, scaling, animation handling, and a stylesheet for capture (Page API).
// Viewport image
await page.screenshot({ path: 'viewport.png', type: 'png' });
// Entire page, including content below the viewport
await page.screenshot({ path: 'full-page.jpg', type: 'jpeg', quality: 85, fullPage: true });
The banner must be dismissed before either capture if the aim is to exercise the consent flow. A screenshot-only stylesheet or locator mask can hide an element in the image, but it does not show that the site’s consent flow was handled or that a preference was recorded. Use those options only when the goal is visual presentation rather than consent interaction (Page API).
Use visual assertions for repeatable regression checks
For a one-off screenshot, page.screenshot() writes an image file. For a visual regression test in Playwright Test, use toHaveScreenshot(); Playwright waits for two consecutive screenshots to match before comparing the last screenshot (PageAssertions).
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →As an Amazon Associate I earn from qualifying purchases.
import { test, expect } from '@playwright/test';
test('page screenshot without consent banner', async ({ page }) => {
await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
const consentButton = page.getByRole('button', { name: 'Reject optional cookies' });
await consentButton.waitFor({ state: 'visible' });
await consentButton.click();
await page.locator('YOUR_BANNER_SELECTOR').waitFor({ state: 'hidden' });
await expect(page).toHaveScreenshot('page-without-banner.png', { fullPage: true });
});
Replace both example locators with the target site’s real controls. Keep the browser version, operating system, headless setting, viewport, and other rendering conditions consistent between generating and comparing reference screenshots: visual output can vary with the host OS, browser version, settings, hardware, power source, and headless mode (Playwright visual comparisons documentation).
Do not confuse a consent banner with a browser dialog
HTML consent banners are page elements and should be handled with locators. JavaScript alert, confirm, and prompt are browser dialogs and use Playwright’s dialog handling API. Dialogs are automatically dismissed by default; if you register a page.on('dialog') handler, that handler must accept or dismiss the dialog or the page can stall (Playwright Dialogs). Adding dialog handling will not dismiss a normal HTML cookie banner.
Troubleshoot failed or inconsistent captures
- Timeout waiting for the button: the selector may not match, the banner may be delayed, or it may not appear in the current context. Inspect the rendered page and choose a locator for the real control; adjust the timeout only if the site legitimately needs more time.
- Click succeeds but the banner remains: the click may have hit a nonfunctional element, opened a preferences panel, or closed only one layer. Wait for the specific overlay to become hidden and handle any additional consent step the site presents.
- Banner appears in only some runs: consent state may be stored in browser context storage. Decide whether the test needs a fresh context or a reused state and configure it consistently.
- Screenshot differs across machines: align browser and operating system, viewport, headless mode, and rendering environment before treating the change as a page regression.
- The page hangs after adding a dialog listener: if the event is a JavaScript dialog, ensure the listener calls
accept()ordismiss(). If it is an HTML banner, remove the dialog listener and use a page locator instead.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. Its clean-capture flow accepts cookie or consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Only clean shots are billed: bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status in headers. AI agents can use its MCP server through tools including take_screenshot, get_page_info, and capture_pdf.
One GET request returns an image or PDF. The example saves a WebP capture of the page:
#1 Best Overall
- FULL HD IPS DISPLAY - Enjoy vibrant, crystal-clear images with 178-degree wide-viewing angles
- AMD RYZEN 3 30 PROCESSOR - Everyday performance you can count on; Multitask, stream, game casually, and edit photos smoothly with responsive power and vibrant HDR visuals
- ENJOY UP TO 14 HOURS AND 15 MINUTES OF BATTERY LIFE - HP Fast Charge restores battery from 0 to 50% in approximately 45 minutes
- AMD RADEON 610M GRAPHICS - Experience smooth entertainment; Built for streaming and multitasking, enjoy realistic visuals and efficient performance for work and play
- STORAGE AND MEMORY - 512 GB PCIe NVMe M.2 SSD offers fast speed and efficient storage; and 8 GB LPDDR5 RAM memory boosts performance with higher bandwidth
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 the request options. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. Sign up for free and get 1,000 screenshots a month with no card.
Quick Recap
Best Value
- 【Powerful Performance】Equipped with an Intel N150 CPU, featuring up to 4.4 GHz, ensuring efficient and powerful multitasking capabilities.
- 【Versatile Connectivity】Stay connected with multiple ports including USB 3.0 Type-C, USB 3.0 Type-A, and a headphone/mic combo jack, with Wi-Fi and Bluetooth for seamless wireless networking.
Rank #4
- Efficient Performance for Everyday Computing: Powered by Intel N150 processor with up to 3.6 GHz Intel Turbo Boost Technology, 6 MB L3 cache, 4 cores, and 4 threads, this HP laptop delivers responsive performance for web browsing, streaming, document editing, and multitasking. Paired with 4GB LPDDR5 RAM and 128GB UFS storage, it handles daily tasks smoothly. Includes 1-year Microsoft 365 Personal subscription for Word, Excel, PowerPoint, and cloud storage to maximize your productivity.
- 14-Inch HD Micro-Edge Display:Enjoy clear visuals on the 14-inch HD (1366 x 768) anti-glare screen with 250-nit brightness and 62.5% sRGB coverage. The micro-edge bezel delivers a 79% screen-to-body ratio in a compact design. An HP True Vision 720p HD camera with noise reduction and dual-array microphones supports clear video calls, remote work, and online learning.
- Modern Connectivity and Wireless Technology: Stay connected with Wi-Fi 6 (2x2) for faster wireless speeds and Bluetooth 5.4 for seamless pairing with accessories. Versatile port selection includes 1 USB Type-C 10Gbps with DisplayPort 1.2 for external displays, 2 USB Type-A 5Gbps ports for peripherals, 1 HDMI 1.4b port, 1 headphone/microphone combo jack, and 1 multi-format SD media card reader. Connect monitors, transfer files quickly, and expand your workspace with ease.
- All-Day Battery Life and Portable Design: Enjoy up to 11 hours of video playback, 7.5 hours of mixed usage, or 7.5 hours of wireless streaming on a single charge, perfect for students and professionals on the go. Weighing just 3.24 lb and measuring 12.76" x 8.86" x 0.71", this lightweight laptop fits easily in backpacks and bags. The stylish willow green top cover with matte finish and natural silver keyboard deck with vertical brushing pattern offer a modern, professional look.
- AI-Enhanced Productivity: Access Microsoft Copilot instantly with the dedicated Copilot key for faster assistance. AI Noise Reduction filters background sounds and improves voice clarity during calls. Dual speakers provide clear audio, while the full-size natural silver keyboard and HP Imagepad support comfortable typing and navigation.
Rank #3
- Stunning 15.6" FHD IPS Display: Experience crisp 1920x1080 resolution on this 15.6 inch laptop with an IPS panel that delivers wide viewing angles and vivid colors. The narrow-bezel design maximizes screen real estate for comfortable viewing on this Win 11 laptop, whether you're studying or working.
- Celeron J4105 Processor & 256GB SSD: Powered by a reliable Celeron J4105 processor paired with 12GB DDR4 memory and a fast 256GB M.2 SSD. This laptop computer supports SSD expansion up to 2TB and TF card expansion up to 1TB, so your storage grows with your needs. Delivers smooth multitasking for daily productivity.
- AI-Powered Win 11 Laptop: Built-in AI features enhance your productivity with smart assistance for writing, summarizing, and task management. Pre-installed with Win 11 and includes Office 365 subscription. This student laptop is backed by 1-year warranty and 24/7 customer support.
- All-Day 7000mAh Battery & 180° Hinge: The high-capacity 7000mAh battery keeps this laptop powered through long classes or meetings. The 180-degree lay-flat hinge lets you share your screen effortlessly during presentations. This durable laptop computer adapts to your dynamic workflow.
- Versatile Connectivity Hub: Equipped with USB 3.2, Type-C, Mini HDMI, and 3.5mm audio jack to connect all your peripherals. Stay online anywhere with high-speed 5G WiFi and Bluetooth 4.2. This college laptop keeps you connected at home, in the library, or on the go.
Rank #2
- Intel Celeron N4120: 4 Cores & Threads, 1.1GHz Base Clock, Up to 2.6GHz Boost Clock, 4MB Cache, Intel UHD Graphics 600. The perfect combination of performance, power consumption, and value helps your device handle multitasking smoothly and reliably with four processing cores to divide up the work.
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.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.




