In Selenium, wait for the website’s actual consent button to become clickable, click the choice you intend to make, wait until the banner is no longer visible, and then save the screenshot. There is no universal cookie-banner selector: the control and the condition that confirms dismissal depend on the site.
Dismiss the banner, verify the page, then capture
This Python example shows the sequence. Replace the illustrative selectors with ones that match the website under test, and choose the consent action that fits your test.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# Illustrative selectors only; inspect the target site's consent UI.
consent_button = (By.CSS_SELECTOR, "button[data-testid='cookie-accept']")
banner = (By.CSS_SELECTOR, "[role='dialog']")
with webdriver.Chrome() as driver:
driver.get("https://example.com")
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable(consent_button)).click()
wait.until(EC.invisibility_of_element_located(banner))
saved = driver.save_screenshot("page.png")
if not saved:
raise OSError("Could not save screenshot")
- Open the target page and define a
WebDriverWaitfor the amount of time appropriate to your test. - Locate the intended consent control using a site-specific selector. Wait for it to be clickable instead of relying on a fixed sleep.
- Click the control, then wait for a meaningful success condition. In this example, the banner must become invisible.
- Capture only after that condition succeeds. If the screenshot is part of a test, treat a timeout as a failure to establish the expected page state rather than silently capturing the still-visible banner.
The CSS selectors in the code are examples, not guaranteed selectors. Inspect the target page’s markup and identify both the consent action and the banner or other page state that indicates the action worked. A site may remove the banner from the document rather than merely hide it; Selenium’s invisibility condition can account for an element that is absent or not visible.
Handle site-specific consent UI
Choose the intended action
Do not assume that “accept” is the right choice for every test or visitor. Select the site’s intended control, such as the choice your test is designed to exercise, and verify the resulting state. Consent interfaces and persistence behavior differ by site.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
If the banner is inside an iframe
Switch the WebDriver context to the relevant iframe before locating the consent button. After interacting with the control, switch back to the main document if subsequent checks or captures require that context. The correct frame and selector must be determined from the target page.
Use state-based waits, not arbitrary delays
A fixed pause can be too short on a slow load and unnecessarily long on a fast one. An explicit wait for clickability followed by a wait for invisibility ties the next step to observable page state. If disappearance is not the right success condition for a site, wait for the site-specific state that confirms the banner was handled.
What Selenium captures and how to save it
driver.save_screenshot("page.png") writes a PNG of the current window and returns a boolean: check it so an I/O failure does not pass unnoticed. This ordinary method captures the current window, not necessarily the entire document.
#1 Best Overall
- Privacy Protection and Lens Care: Avoid private information from hacking while preventing dust-fall and scratching of the camera lens
- Multiple Compatibility: Suitable for Logitech webcam C920x, C920, C922, C930e, C922x Pro Stream HD Camera
- Artful Design: Modeled and designed exclusively to fit the above devices from Logitech and make it more stylish
- Easy Flip Mechanism: Can be turned 180 angle and easily take the cover off when flipping more than 180
- Simple Installation: Attaches securely to your Logitech webcam without leaving residue, allowing for quick and hassle-free setup
- Save a file: use
save_screenshot(filename)when the test needs a PNG artifact on disk. - Process image bytes: use
get_screenshot_as_png()when the program needs PNG data directly. - Embed an image: use
get_screenshot_as_base64()when base64 output is useful to the caller.
If you need a full-document capture rather than the current window, do not assume the ordinary current-window method provides it. Selenium’s Firefox driver documentation separately lists full-document screenshot methods; support depends on the browser and driver API in use.
When direct cookie setup is appropriate
Selenium can add, read, and delete cookies, but the browser must first be on a domain for which a cookie is valid. Seeding a known cookie can be useful in a controlled test whose purpose is to start from a known state, but it is not a universal replacement for clicking the banner: the site may use different persistence or consent mechanisms, and setting a cookie does not guarantee the UI will disappear.
| Approach | Best suited to | Key consideration |
|---|---|---|
| Click the visible consent control | Testing the user-facing consent flow | Requires the site’s actual locator and a verified post-click condition. |
| Seed a cookie | A controlled test that intentionally begins with known browser state | Requires a valid domain and known cookie behavior; does not guarantee the banner is dismissed. |
Troubleshoot failed captures
- Element not found: the selector may not match the site, the banner may not have loaded yet, or the control may be in an iframe. Inspect the page and switch into the correct frame before locating it.
- Clickability wait times out: verify that the chosen control exists, is enabled, and is not covered by another element. Confirm that the page finished rendering the consent UI.
- Banner invisibility wait times out: check whether the selector identifies the right banner and whether the click produced the expected consent state. If the banner stays visible by design, wait for another observable success condition.
- Screenshot returns false: check the output path and whether the process can write there;
save_screenshotreports an I/O failure with its return value. - Image omits lower-page content: the standard method captures the current window. Use a browser-specific full-document capability if the test requires the whole page.
Or skip the browser setup
ScreenshotNeo can take a screenshot from one GET request. Its clean-shot workflow accepts cookie or 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 and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents.
Example cURL request (replace the URL with the page you need):
Rank #2
- Webcam comes with privacy shutter – puts you in control of what you show and protects the lens with a snugly fitting cover. Does not include the 3-month XSplit VCam license.
- Full HD 1080P video calls – premium video quality that makes you look like a Pro
- Full HD 1080P video Recording – a glass lens and full HD mean your recorded videos are crisp and vibrantly colored
- HD autofocus and light Correction – enjoy razor-sharp high Def in every environment
- Stereo audio with dual mics – capture natural sound on calls and recorded videos
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 options. The free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Sign up for 1,000 free screenshots a month, with no card required.
Do these 3 things before closing this tab:
1Repair Windows errors before they cause bigger problems2Fix the driver behind crashes, sound loss and screen glitches3Clear out junk files and repair common Windows errorsFrequently Asked Questions
Can I use the same cookie-banner selector on every website?
No. Consent UI markup and selectors are site-specific; inspect the target page and use its actual control.
Rank #3
- Privacy Protection: CloudValley webcam cover is designed for those who prioritize privacy, security, and peace of mind when using laptops, tablets, and computers
- Fashion Design: The space aluminum alloy webcam cover features a subtle design which compliments the beautiful aesthetic of top devices
- Ultra-Thin Design: Measures only 0.023 (0.6 mm) inch thin, ensuring it does not interfere with closing your laptop or device while providing reliable camera coverage
- Broad Compatibility: Works flawlessly with most laptops (MacBook, HP, Dell, Asus, Acer, Lenovo), All-in-One PCs and leading tablets including iPad, Surface Pro, Galaxy Tab, Fire HD, and Google Pixel Tablet
- Simple to Use: Only need to align to the webcam, attach and press it firmly for 15 seconds. Does not interfere with web use or indicator light
Does Selenium automatically accept cookies when I take a screenshot?
No. The script must interact with the intended consent control or otherwise establish the site-specific state before capture.
Quick Recap
Best Value
- 【Multiple Compatibility】Compatible For Logit HD Pro Webcam C920 C930e and C922 C922x Pro
- 【Protects Privacy】This webcam cover conveniently blocks your camera cover to protect your privacy
- 【Protecting the Camera】Protect the Webcam Clean,Farewell the dust
- 【Note】This item don't Compatible for Logit HD Pro Webcam C910 and B910 and other Webcam
- 【Package contents】 1 X Webcam Protects Lens Cap Hood Cover(Webcam not Included)
Rank #4
- Compatible with the following models of Logitech webcam: C920, C920X, C920S, C922, C922X, C930e, Logitech 1080p Pro Stream Webcam
- Protect the Webcam Clean from dust
- Protect your privacy when you need to
- Package includes: 1 X Black Viecam Webcam Privacy Shutter
- Note: Webcam is NOT included
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.

