How to take screenshots of Indian government web portals with Selenium in Bengali
Save a government portal’s current browser view as a PNG with Selenium. Learn what the capture includes, how to handle language and verification screens, and how to troubleshoot common issues.
Use Selenium’s Python driver.save_screenshot("portal.png") method to save the browser’s current window as a PNG. It captures the rendered browser view at the time you call it; it does not translate the page, guarantee a full-page capture, or guarantee that a particular government portal permits scripted access. This guide is written in English about a Bengali-language search topic: Selenium instructions do not change the language the portal displays.
The basic flow is: install Selenium, open a permitted public page, wait for the content you need to appear, and save the screenshot. Selenium returns a Boolean from save_screenshot, so check it and handle a failed file write. See the official Selenium Python WebDriver API.
1. Install Selenium and prepare the browser
Use a supported Python installation and install Selenium in the environment that will run the script:
python -m pip install selenium
Recent Selenium versions can manage browser drivers through Selenium Manager when the relevant browser is installed. If your environment does not support automatic driver management, install and configure the driver for your chosen browser according to Selenium’s official documentation. The actual browser and driver setup depends on your operating system and deployment environment.
Choose a public page that you are permitted to access, and check that portal’s published terms and access instructions. Do not assume that every portal allows automation. Set the URL, viewport, and output path for your own use.
2. Save the current browser window as a PNG
This runnable example opens the configurable URL, waits for the document to reach its complete ready state, and saves a PNG. A complete document state does not prove that every page element, delayed widget, or image has finished rendering; inspect the result and use a targeted wait when needed.
import os
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
URL = os.environ.get("PORTAL_URL", "https://example.gov.in/")
OUTPUT = os.environ.get("SCREENSHOT_PATH", "portal.png")
options = webdriver.ChromeOptions()
# For a headless run, uncomment the next line:
# options.add_argument("--headless=new")
driver = webdriver.Chrome(options=options)
try:
driver.set_window_size(1440, 1000)
driver.get(URL)
WebDriverWait(driver, 30).until(
lambda browser: browser.execute_script("return document.readyState") == "complete"
)
saved = driver.save_screenshot(OUTPUT)
if not saved:
raise OSError(f"Could not save screenshot to {OUTPUT!r}")
print(f"Saved current-window screenshot to {OUTPUT}")
finally:
driver.quit()
Remove the accidental leading space before driver = webdriver.Chrome(...) if copying this into Python; the corrected line is shown here for clarity:
driver = webdriver.Chrome(options=options)
Run it with a target and destination of your choice:
PORTAL_URL="https://example.gov.in/" SCREENSHOT_PATH="portal.png" python capture.py
Replace the example URL with a permitted page. The sample does not claim that an Indian government portal was tested. Use a full output path if running from a scheduler or another working directory; Selenium’s API documentation recommends full paths.
3. Decide what the screenshot should contain
Current window versus full document
save_screenshot captures the current window. For a long page, do not assume this includes content below the visible browser area. The Firefox WebDriver API separately documents save_full_page_screenshot(filename) for full-document capture. That method is documented for Firefox; check support in the browser and Selenium version you actually use before relying on it.
# Firefox-specific documented full-page method; confirm support in your setup.
from selenium import webdriver
driver = webdriver.Firefox()
try:
driver.get("https://example.gov.in/")
if not driver.save_full_page_screenshot("portal-full.png"):
raise OSError("Could not save full-page screenshot")
finally:
driver.quit()
For a normal current-window capture, set the viewport before navigating or capturing:
driver.set_window_size(1440, 1000)
# Navigate, wait for the intended view, then:
driver.save_screenshot("portal.png")
Viewport dimensions affect responsive layout and how much of the page is visible. Pick dimensions that match the intended review or record. Do not describe a window capture as a full-page record.
Wait for the content that matters
Pages can render content after the document reports complete. Prefer waiting for a meaningful, visible element on the specific page rather than adding a fixed sleep to every script. Since portal markup differs, choose a selector only after inspecting the page and respecting its access instructions.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
# Replace the selector with a stable element on the page you are permitted to access.
WebDriverWait(driver, 30).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main"))
)
driver.save_screenshot("portal.png")
If the page has a language selector, choose the language through the portal’s supported controls before capture. Selenium records what the browser renders; its screenshot method does not translate text. Page language choices, layout, and accessibility features depend on the individual portal. The Government of India’s Guidelines for Indian Government Websites and apps (GIGW) identify language and accessibility as important considerations for government sites.
4. Handle CAPTCHA and human-verification screens appropriately
If a CAPTCHA or other human-verification challenge appears, stop the automated flow and use the portal’s permitted human-access route. Do not try to automate answers, evade the challenge, or treat bypassing verification as a screenshot step. GIGW discusses accessible alternatives for CAPTCHA; that accessibility guidance is not permission to circumvent a portal’s human-verification control.
If you need a record of the page as presented, follow the site’s permitted instructions and capture only through an authorized route. A screenshot made while verification is pending will show that state, not the content behind it.
5. Capture image data instead of writing a file
The WebDriver API also provides PNG bytes and a base64-encoded PNG string. Use bytes when another part of your application handles image data directly; use base64 when the receiving format expects an encoded string. These methods have different output forms, so choose based on the interface you need rather than assuming one is faster.
# PNG bytes
png_bytes = driver.get_screenshot_as_png()
with open("portal.png", "wb") as image_file:
image_file.write(png_bytes)
# Base64 text, for a consumer that expects an encoded string
png_base64 = driver.get_screenshot_as_base64()
The API documents save_screenshot as returning False on an I/O error and True otherwise. If using the bytes or base64 methods, the screenshot data is returned to your code; saving it to a file then becomes your responsibility.
6. Troubleshoot common problems
| Symptom | Likely cause | What to do |
|---|---|---|
save_screenshot returns False |
The file could not be written, commonly because the destination path is unavailable or not writable. | Use a full path, check directory permissions, and ensure the destination directory exists. |
| File exists but is blank or incomplete | The capture ran before the relevant content rendered, or the page is still loading dynamic content. | Wait for a relevant visible element or a documented page state, then capture. Inspect the image to confirm the required content is present. |
| Lower part of a long page is missing | save_screenshot captures the current window rather than promising a full-document image. |
Use Firefox’s documented full-page method where supported, or verify a full-page option for your browser and Selenium version. |
| Screenshot shows a CAPTCHA or access-denied page | The portal presented a human-verification or access-control state. | Stop automation and follow the portal’s permitted human-access route and published instructions. Do not bypass the control. |
| Browser or driver fails to start | The browser is missing, the driver setup is incompatible, or the runtime cannot launch a graphical browser. | Install a supported browser, follow Selenium’s driver setup guidance for the environment, and use a headless configuration only where appropriate. |
| Wrong language or unexpected layout | The portal’s current language, viewport, or responsive layout differs from the intended capture. | Select the language through the site’s own controls and set a deliberate viewport before capturing. Selenium will not translate the page. |
| Output is saved in an unexpected folder | A relative path is resolved from the process working directory, which may differ in scheduled jobs. | Set an absolute output path and create its parent directory as part of your application setup. |
7. Reliability, performance, and handling the output
- Use explicit waits: waiting for the element you need makes the capture condition clearer than an arbitrary delay. Set a finite timeout and handle a timeout as a failed capture.
- Make the capture repeatable: define the URL, viewport, output location, browser choice, and wait condition in configuration. Record which URL and time correspond to each saved file when that context matters.
- Always close the browser: use
try/finallyand calldriver.quit()so the browser session is cleaned up after success or failure. - Check the result: verify the Boolean return value for file saves and review the image for the expected language, page state, and capture scope.
- Respect portal access rules: avoid excessive repeated requests, stop when a portal presents a challenge, and follow its published terms and instructions. Selenium does not guarantee that every portal permits scripted access.
- Plan storage: PNG output is a file or image payload your workflow must store and manage. Choose a clear retention policy when screenshots contain personal, account, or otherwise sensitive information.
The supplied Selenium API and government guidance do not provide a benchmark for capture speed, a success rate across portals, or a universal permission rule. Performance depends on the page, browser, machine, and wait condition; measure in your own permitted environment if those figures matter.
8. Or skip the browser setup
If the goal is simply to request a screenshot, ScreenshotNeo is a website screenshot API and MCP server from Yorker Media. A single GET request accepts a URL and returns a PNG, JPEG, WebP, or PDF. See the ScreenshotNeo API documentation for parameters and setup.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.gov.in/ -o shot.webp
import requests
r = requests.get(
"https://api.screenshotneo.com/v1/shot",
params={"access_key": "YOUR_API_KEY", "url": "https://example.gov.in/"},
timeout=90,
)
r.raise_for_status()
with open("shot.webp", "wb") as image_file:
image_file.write(r.content)
const q = new URLSearchParams({
access_key: 'YOUR_API_KEY',
url: 'https://example.gov.in/'
});
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const image = Buffer.from(await res.arrayBuffer());
await import('node:fs/promises').then(fs => fs.writeFile('shot.webp', image));
ScreenshotNeo can accept cookie or consent banners and remove more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each of those steps can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and responses identify the page verdict and billing status in headers. Its MCP server offers take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Create a free ScreenshotNeo account to start with 1,000 screenshots per month and no card.
9. Frequently asked questions
Does this method save a PNG or a JPEG?
save_screenshot saves PNG. Use an image conversion step if another format is required.
Will the screenshot be in Bengali?
Only if the page itself is rendered in Bengali. Selenium captures the displayed browser view and does not translate portal content.
Can I automate a portal after logging in?
That depends on the portal’s published rules and permitted access route. This guide does not establish permission for any specific portal or account workflow.
Can I use the screenshot as an official record?
A screenshot is an image of a browser view. Whether it is accepted as an official record depends on the relevant institution and process; confirm their requirements.


