How to Accept a Cookie Notice Before Screenshotting an Indian Government Website
Choose the cookie settings the task requires, save them, and verify the page before capturing it. Here is a careful browser workflow and runnable Playwright code.
To accept a cookie notice before screenshotting an Indian government website, open the target page, inspect the notice or settings, choose the option required for your task, save the choice if the site offers a save control, and confirm the notice has closed before capturing. Do not assume that “Accept all” is required: some sites distinguish essential cookies from optional ones, and the right choice depends on your task and privacy preference.
Cookie notices and their behavior vary by site. The National Portal of India and Department of Economic Affairs show essential and optional categories with a save-preferences action. The ICCR privacy policy says its site stores whether a visitor accepted or declined the notice in local storage so it will not be shown again. The PMO says some login or customizable sections may not work properly if cookies are refused. These are examples of site-specific behavior, not a universal rule for every government website. National Portal cookie settings, DEA cookie settings, ICCR privacy policy, PMO website policies.
Choose the cookie option that fits the capture
- Open the exact page you need to document, rather than a homepage if the target is a deeper page.
- Read the banner or open its settings. Note which categories are essential and which are optional.
- Decide what the screenshot needs. If the page only needs to display public information, optional functionality cookies may not be necessary. If the task requires a login or a personalized feature, check whether the site says cookies are needed.
- Choose the corresponding accept, decline, or customize control. Use “Accept all” only when it matches the task and your intended choice.
- If you changed categories, press the site’s save button, when provided. Both the National Portal and DEA settings pages show a save-preferences control.
- Wait for the notice to close, then verify the intended content is visible. If it remains, inspect whether the site requires a separate confirmation or whether another overlay is present.
- Capture the page. For records, keep the page URL and capture time alongside the image so another person can identify what was documented.
For evidence that others need to interpret, preserve enough context to identify the page and its content. India’s government website guidelines include guidance about ownership information, information currency, and browser and display testing; they do not prescribe one universal cookie-notice interaction. See the Guidelines for Indian Government Websites and apps (GIGW).
Automate the choice with Python and Playwright
Automation should make an explicit choice, not blindly click the first button containing “accept.” The following script takes the requested action from an environment variable, tries common button labels, then saves a screenshot after checking that the page loaded. Government sites can use different labels and custom controls, so inspect the actual notice and adjust the label list for the target site. This does not bypass a login, CAPTCHA, or other access control.
python -m pip install playwright
python -m playwright install chromium
# Set one of: accept_all, essential_only, customize
COOKIE_ACTION=essential_only TARGET_URL=https://www.india.gov.in/ python capture.py
# capture.py
import os
from pathlib import Path
from playwright.sync_api import sync_playwright, TimeoutError as PlaywrightTimeoutError
url = os.environ.get("TARGET_URL", "https://www.india.gov.in/")
action = os.environ.get("COOKIE_ACTION", "essential_only")
if action not in {"accept_all", "essential_only", "customize"}:
raise SystemExit("COOKIE_ACTION must be accept_all, essential_only, or customize")
# These labels are examples. Inspect the real site and update them as needed.
labels = {
"accept_all": ["Accept all", "Accept All Cookies", "Agree"],
"essential_only": ["Reject optional", "Essential only", "Necessary only", "Decline optional"],
"customize": ["Cookie settings", "Manage preferences", "Customize"],
}
with sync_playwright() as p:
browser = p.chromium.launch(headless=True)
page = browser.new_page(viewport={"width": 1440, "height": 1000}, device_scale_factor=1)
response = page.goto(url, wait_until="domcontentloaded", timeout=60000)
if response and response.status >= 400:
raise SystemExit(f"Navigation returned HTTP {response.status}: {url}")
# Give client-rendered banners time to appear. A site-specific locator may be more reliable.
try:
page.get_by_role("button", name="Cookie", exact=False).first.wait_for(timeout=2500)
except PlaywrightTimeoutError:
pass
clicked = False
for label in labels[action]:
button = page.get_by_role("button", name=label, exact=True)
try:
if button.count() and button.first.is_visible():
button.first.click(timeout=3000)
clicked = True
break
except PlaywrightTimeoutError:
continue
if action == "customize" and clicked:
print("Settings opened. Select the required categories and save them using site-specific controls.")
input("After choosing and saving the preferences in the open browser, press Enter here to capture... ")
elif not clicked:
print("No matching consent button was found. Inspect the page and configure a site-specific locator.")
input("After handling the notice in the open browser, press Enter here to capture... ")
page.wait_for_timeout(500)
page.screenshot(path="government-page.png", full_page=True)
print(f"Saved government-page.png from {page.url}")
browser.close()
The example uses a visible human decision as a fallback if the labels differ. For unattended production runs, implement a site-specific consent handler, check its result, and fail the job when it cannot confirm the desired choice. Do not silently treat a missing banner or unmatched button as accepted consent.
Browser workflow options and edge cases
- Banner button versus settings panel: A banner may provide direct accept or decline choices, while a settings screen can expose individual categories. Choose categories there, then use the save control.
- Essential and optional categories: A page may mark essential cookies as necessary for site operation and offer optional functionality separately. The National Portal describes optional functionality such as retaining searches and feedback-form information. Do not infer that optional means required for viewing the page.
- Login or customization: The PMO policy warns that some login or customizable sections may need cookies. If the target depends on one, follow the site’s stated requirements and document the choice.
- Persistence: A saved preference may be remembered. ICCR describes using local storage for the accept-or-decline choice. Persistence is implementation-specific; a fresh browser profile may show the notice again.
- Multiple overlays: A cookie panel can coexist with a newsletter popup, chat widget, or other notice. Confirm which overlay blocks the content and handle it according to the task.
- Dynamic pages: A notice or page content can load after initial HTML. Wait for the relevant element or a short, bounded delay rather than capturing immediately after navigation.
- Evidence needs: If a screenshot is part of a report, record the URL, time, selected preference, and browser or viewport details separately. Do not claim a screenshot establishes what consent was previously stored unless your workflow records that state.
Common problems and fixes
| Problem | Likely cause | Fix |
|---|---|---|
| The notice still covers the page | The selection was not saved, or the site needs a separate confirmation. | Reopen settings, choose the intended categories, use the save control, and verify the overlay closes. |
| The expected button is not found | The site uses different wording, a link, or a custom control rather than a standard button. | Inspect the rendered page and use a locator tied to the actual label or accessible name. Avoid a broad selector that could click an unrelated control. |
| The page behaves differently after declining | A specific login or customization feature may rely on cookies. | Check the site’s policy and task requirements. If that feature is necessary, make the corresponding choice and record it. |
| The banner returns in a later run | The browser profile is new, storage was cleared, or the site does not persist the choice. | Reuse a controlled browser profile when appropriate, or handle the consent step on each run. Keep profiles isolated between unrelated users. |
| The screenshot is blank or incomplete | Navigation or client rendering had not finished, or a network failure blocked resources. | Check the response and page content, wait for a meaningful selector, and retry only transient failures with a limit. |
| The automated click selects the wrong choice | Labels were ambiguous or the locator matched more than one element. | Use exact accessible names and scope the locator to the consent dialog. Log which choice was selected. |
Performance, reliability, and cost
For a one-off capture, manual browser interaction is often simplest. For repeat captures, Playwright avoids repeating setup, but the site’s changing markup and consent wording can break brittle selectors. Prefer exact labels or accessible roles, wait on a meaningful page element, and make failed consent handling visible in job logs. A full-page screenshot can take longer and use more memory than a viewport capture, particularly on long pages.
Consent preferences are browser state. A persistent profile can avoid repeated prompts where the site remembers a choice, but shared profiles can leak state between tasks. Use a dedicated profile per workflow and do not store session data longer than necessary. Headless and headed browsers may render differently; for screenshots used as evidence, keep viewport and browser settings consistent and inspect the output.
Self-hosting browser automation means maintaining the browser, dependencies, execution environment, and retries. A screenshot API can remove that browser setup; compare the cost against capture volume and the time spent maintaining automation. Do not treat a screenshot service as a substitute for making the correct consent choice when your task requires a specific preference.
Or skip the browser setup
ScreenshotNeo is a website screenshot API and MCP server by Yorker Media. For a one-call capture, provide the page URL and API key. See the ScreenshotNeo API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://www.india.gov.in/ -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://www.india.gov.in/"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://www.india.gov.in/' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
ScreenshotNeo accepts cookie and consent banners like a visitor and removes 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 tools for AI agents. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 screenshots. Try it with the free ScreenshotNeo account.
FAQ
Do I have to accept all cookies to take a screenshot?
No general rule says you must accept all cookies. Check the target site’s categories and choose according to the task and your privacy preference.
Will declining cookies always hide the notice next time?
No. Some sites remember the choice, but persistence depends on the site and browser state. ICCR documents local-storage persistence for its own notice.
Can a screenshot prove that I accepted a cookie notice?
A screenshot can show the page after the notice closes, but it does not by itself establish which preference was stored. Record the choice and capture context separately when that matters.
Does GIGW specify how to click a cookie banner?
The cited GIGW guidance addresses website quality and context, including ownership and information currency. It does not prescribe one universal consent-banner workflow.


