To capture a website after a cookie-banner choice in Selenium, locate and click the site’s actual consent control, wait for an observable post-choice state, then save the browser window. There is no universal selector or consent cookie: the right choice and the markup depend on the website and on what your screenshot needs to show.
Choose the right consent action before coding
Decide what the capture is meant to document: accepting cookies, rejecting them, opening settings, or another option the site offers. Use that actual control. Hiding or removing the banner is not evidence that a consent choice was made.
This distinction matters especially in tests of the user-visible consent flow. Clicking the interface records the same kind of action a visitor takes; preloading a cookie is appropriate only when the site’s consent format and meaning are known and the test is deliberately setting that state.
Inspect the banner and identify a stable locator
Cookie banners are implemented by individual sites, so inspect the target page’s real interface and DOM. Selenium can locate elements by ID, name, XPath, CSS selector, class, tag, or link text. Prefer a locator tied to the actual accessible label or a stable site attribute, rather than guessing a generic selector. See Selenium’s element interaction documentation.
The example below uses a button labelled “Reject all” only as an illustration. Replace it with the exact control and locator found on your target site. If the intended action is acceptance or settings, target that control instead.
As an Amazon Associate I earn from qualifying purchases.
Python example: make a choice, wait, and save the screenshot
Navigate to the target page before this sequence. The explicit waits synchronize with a changing page state; the banner selector must also be verified against the site.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# driver has already navigated to the target page.
wait = WebDriverWait(driver, 15)
# Replace this locator with the actual consent control on the site.
choice = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//button[normalize-space()='Reject all']")
))
choice.click()
# Replace with a verified banner selector and a condition that
# represents the site's completed post-choice state.
wait.until(EC.invisibility_of_element_located(
(By.CSS_SELECTOR, "YOUR_VERIFIED_BANNER_SELECTOR")
))
driver.save_screenshot("website-after-consent.png")
This is a pattern, not a universal script: the control text, banner markup, and behavior after a choice vary. If the banner closes but the page then updates or reloads, wait for an additional site-specific condition that represents the state you want to capture. Selenium’s waits documentation covers synchronization with changing page state.
Handle banners inside an iframe
If inspection shows the consent interface inside an iframe, switch into that frame before locating or clicking its controls. After the interaction, return to the main document before checking the page-level state or capturing the page.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
wait = WebDriverWait(driver, 15)
# Replace with a verified iframe locator.
frame = wait.until(EC.presence_of_element_located(
(By.CSS_SELECTOR, "YOUR_VERIFIED_IFRAME_SELECTOR")
))
driver.switch_to.frame(frame)
# Replace with the actual choice control inside the frame.
choice = wait.until(EC.element_to_be_clickable(
(By.XPATH, "//button[normalize-space()='Reject all']")
))
choice.click()
driver.switch_to.default_content()
# Wait for an observable, site-appropriate result in the main page.
wait.until(EC.invisibility_of_element_located(
(By.CSS_SELECTOR, "YOUR_VERIFIED_BANNER_OR_FRAME_SELECTOR")
))
driver.save_screenshot("website-after-consent.png")
Use the frame actually containing the banner; nested frames may require switching through each parent in order. Selenium documents frame switching in its frame interaction guide.
Set consistent screenshot dimensions
Selenium’s Python WebDriver API saves the current browser window as a PNG. For repeatable dimensions, set the window size before navigating or capturing, and use the same dimensions across runs.
#1 Best Overall
- 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
driver.set_window_size(1440, 1000)
# Navigate, make the consent choice, and wait for the target state.
driver.save_screenshot("website-after-consent.png")
The screenshot represents the browser’s current window at capture time; it is not automatically a full-page capture. The Python WebDriver 4.50.0 API documents save_screenshot and window sizing.
Recommended Free Tools
When setting a cookie directly is appropriate
Selenium exposes cookie operations, including adding and deleting cookies. A cookie can only be added while the browser is on a domain for which it is valid. But the generic API does not tell you a site’s consent-cookie name, value, domain, or semantics. Get those details from the target site’s implementation or a verified test fixture; do not guess them or assume insertion is equivalent to clicking a choice. See Selenium’s cookie documentation.
Rank #2
- 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 direct UI interaction when the purpose is to capture or test a visitor’s banner choice. Use a verified cookie only when the test intentionally sets a known consent state and the site’s implementation establishes what that cookie means.
Troubleshoot common failures
- Element not found: Confirm the banner has appeared, inspect the actual DOM, and check whether it is inside an iframe. Use the correct frame context and a locator matching the real control.
- The element appears too late: Wait for the element to become clickable or for another meaningful state. A fixed pause can be either too short or unnecessarily long; Selenium’s explicit waits are condition-based.
- The screenshot still shows the banner: Verify that the intended control was activated, then wait for the banner’s actual post-choice state before capture. Do not treat removing the banner from the DOM as proof of consent.
- The choice does not persist: Check the site’s consent implementation, session, and domain behavior. Selenium’s cookie API provides low-level browser access, not a portable consent policy.
- Screenshot dimensions vary: Set the browser window size explicitly and keep it consistent between runs.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server. A single GET request can return an image or PDF; for captures, it can accept cookie/consent banners as a visitor and remove known consent platforms, newsletter popups, and chat widgets before the shot. Those steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents and other MCP clients. The free plan includes 1,000 shots a month with no card; paid plans start at $5 for 3,000 shots. This is useful when you need a clean capture rather than a Selenium test of a specific consent choice.
For API options, see the ScreenshotNeo documentation. Example cURL request:
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
Replace the target URL with the page you want to capture and provide an API key. Sign up for 1,000 free screenshots a month, with no card required.
Rank #3
- 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.
Frequently Asked Questions
Does dismissing a cookie banner mean consent was recorded?
Not necessarily. Use the site’s actual choice control and verify its resulting state; hiding or removing the banner alone does not establish that a choice was made.
Can Selenium use the same cookie-banner selector on every site?
No. The banner’s controls and markup are site-specific, so inspect the actual page and use a verified locator.
Is cookie preloading better than clicking the banner?
Neither is universally better. Clicking is the more representative approach when testing a visitor’s visible choice; preloading is suitable when the site’s cookie format and semantics are verified and the test intentionally sets that state.
The Tool Desk
Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Quick Recap
Best Value
- 【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.
Rank #4
- 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
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.




