How to Take Selenium Screenshots of a Web Page in Tamil Using Headless Chrome
Capture a web page with Selenium and headless Chrome, save a PNG, and check that Tamil text renders correctly in your runtime.
Use Selenium to start Chrome with --headless, open the page, set the viewport you want, and call driver.save_screenshot() with a writable .png path. That method captures the current browser window. Tamil text depends on the fonts available where Chrome runs, so verify the resulting PNG in the same environment you use for automation.
1. Install Selenium and prepare Chrome
Install Selenium in the Python environment that will run the script:
python -m pip install selenium
Selenium Manager can help Selenium obtain a compatible browser driver in common setups. Your runtime still needs Chrome or Chromium installed and runnable. In containers and CI, make sure the browser, its required system libraries, and any needed fonts exist in the actual image or host. Browser and driver version compatibility depends on the versions installed in your environment.
Chrome’s current headless mode is enabled with --headless. Since Chrome 112, headless and regular Chrome use the same browser code. Do not assume the older --headless=new spelling is universally required. See the Chrome Headless documentation and Selenium Python Chromium WebDriver API.
2. Capture the current browser window with Python
This complete script opens a page, sets a predictable window size, saves a PNG to an absolute path, checks Selenium’s return value, and always closes the browser:
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
url = "https://example.com"
output = Path("screenshots/page.png").resolve()
output.parent.mkdir(parents=True, exist_ok=True)
options = Options()
options.add_argument("--headless")
options.add_argument("--window-size=1365,900")
driver = webdriver.Chrome(options=options)
try:
driver.get(url)
saved = driver.save_screenshot(str(output))
if not saved:
raise OSError(f"Could not save screenshot to {output}")
print(f"Saved screenshot to {output}")
finally:
driver.quit()
Change url to the page you need. The output parent directory is created if it does not exist. The filename should end in .png; Selenium documents that save_screenshot(filename) saves the current window to a PNG, recommends a full path, and returns False on an I/O error.
Wait for the page state you need
driver.get() returns according to the page load strategy and browser navigation behavior, but client-side rendering, delayed content, and web fonts can finish later. Prefer waiting for a page-specific condition over an arbitrary sleep. For example, wait for a known element:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# After driver.get(url):
WebDriverWait(driver, 20).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "main article"))
)
driver.save_screenshot(str(output))
If your page exposes a meaningful font readiness condition, you can wait for the browser’s FontFaceSet before capture:
WebDriverWait(driver, 20).until(
lambda d: d.execute_script("return document.fonts ? document.fonts.status === 'loaded' : true")
)
This only tells you that the document’s known web fonts have reached the loaded state; it does not prove that a Tamil-capable font exists or that every glyph looks right. Inspect the image.
3. Make Tamil render correctly
Headless mode does not itself provide Tamil fonts. Chrome uses fonts available to the operating system or container, along with CSS font choices and fallback behavior. If Tamil characters appear as empty boxes, missing-glyph symbols, or an unexpected fallback style, check the environment in which the WebDriver process actually launches.
- Open a page or local test fixture containing representative Tamil text in the same Chrome runtime.
- Check whether the intended Tamil-capable font is installed and visible to that runtime. Installation steps differ by Linux distribution, container image, and operating system; confirm them for your specific base image.
- Restart or relaunch Chrome after changing system fonts if the browser process was already running.
- Wait for the page’s relevant content and web fonts, then capture again.
- Open the PNG and inspect Tamil glyphs, punctuation, line wrapping, and fallback appearance.
A page’s CSS may request a font that is unavailable, and a web font may fail to load because of network, access-control, or page configuration issues. Browser fallback can still display some text while changing its appearance. Do not treat a successful file save as proof of correct Tamil rendering.
4. Control the screenshot dimensions and scope
Viewport size
--window-size=1365,900 sets the browser window dimensions used for the capture. Choose dimensions that match the layout you want to inspect. Responsive breakpoints can change the page when the viewport changes, so keep the size stable across runs if you compare screenshots. The image is a capture of the current window, not automatically the entire scrollable document.
Capture a single element
For a component such as a chart, article, or card, locate the element and use Selenium’s element screenshot method:
from selenium.webdriver.common.by import By
article = driver.find_element(By.CSS_SELECTOR, "main article")
article.screenshot(str(output.parent / "article.png"))
Selenium documents element.screenshot('./image.png') for capturing an individual element in its browser documentation. Ensure the element is present and visible before capturing it. This is an element image, not a full-page capture.
Full-page capture
save_screenshot() is documented as a current-window capture; it does not promise to include the full scrollable document. Chrome’s headless CLI documentation says full-page capture takes additional steps. If you need a full-page Selenium image, use a separately verified approach appropriate to your browser and Selenium version, and validate the resulting dimensions and content. Do not infer full-page coverage from a successful call to save_screenshot().
5. Alternative: use Chrome’s headless command line
For a one-off URL capture that does not need Selenium interactions or test setup, Chrome’s CLI has a separate --screenshot option. This is not a Selenium method:
google-chrome --headless --window-size=1365,900 --screenshot=page.png https://example.com
The executable name and installation path vary by environment. Chrome’s Headless CLI reference documents --screenshot, --window-size, and a --timeout option for bounding the wait before capture. Use Selenium when you need to establish state by clicking, logging in, setting values, or asserting page behavior before the screenshot.
6. Troubleshoot common failures
| Symptom | Likely cause | What to do |
|---|---|---|
| No PNG appears | The destination directory is missing, unwritable, or the filename is unsuitable. | Use an absolute path, create the parent directory, ensure the process can write there, use a .png filename, and check the boolean return value. |
| Chrome fails to start | Chrome is missing, cannot run in the environment, or the browser and driver setup is incompatible. | Confirm Chrome/Chromium is installed and runnable in that runtime; inspect Selenium’s startup error and check the installed browser and driver versions. |
| The PNG is blank or shows an incomplete page | The screenshot ran before relevant content rendered, navigation failed, or the page depends on delayed JavaScript. | Wait for a meaningful element or page-specific condition, and confirm navigation reached the expected page before saving. |
| Tamil appears as boxes or unusual glyphs | A Tamil-capable font is unavailable to Chrome, the requested web font did not load, or fallback differs from expectation. | Check fonts in the actual runtime, verify the page’s font loading, relaunch Chrome after font changes, and inspect a fresh PNG. |
| Screenshot is clipped | The viewport is smaller than the content, or the target is outside the visible window. | Set an intentional window size. For an element capture, wait for and locate the right element. For full-page output, use a separately verified full-page technique. |
| Output differs between local and CI | Different browser versions, viewport sizes, fonts, device scaling, or page timing. | Align those environment inputs and use explicit waits; compare the actual PNG dimensions and glyph rendering. |
7. Reliability, performance, and cost considerations
Each capture starts or uses a browser process and waits for navigation and rendering, so page complexity, remote resources, and wait conditions affect completion time. Reuse a WebDriver session when capturing multiple pages in one controlled job, but reset page state as needed and always call quit() when the job ends. A fixed sleep can waste time on fast pages and still be too short on slow pages; condition-based waits make the capture depend on the state you actually need.
For reliable results, keep the browser version, viewport, font environment, and target page state consistent. Treat external page availability and web font loading as dependencies that may fail. Check navigation and screenshot outcomes, retain useful error details, and inspect representative outputs when changing the runtime.
Self-hosted Selenium has no per-screenshot API charge, but it uses compute, storage, and maintenance time for Chrome, drivers, dependencies, and fonts. For a simple capture, Chrome’s CLI avoids writing WebDriver automation. If you need managed capture, ScreenshotNeo offers a one-request screenshot API with free and paid monthly quotas; current plan details are listed below.
Or skip the browser setup
If you only need the screenshot and do not need Selenium to drive page interactions, call the ScreenshotNeo website screenshot API. See the API documentation for request options.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://example.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://example.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000 screenshots. Sign up for free and get 1,000 screenshots a month with no card.
FAQ
Does headless Chrome change how Tamil text is encoded?
No special Selenium encoding step is needed for a normal web page. The key screenshot concern is whether Chrome has a suitable font and has finished rendering the page.
Can I save the screenshot as JPEG with Selenium’s method?
The documented save_screenshot() method writes PNG. Convert the PNG separately if another image format is required.
Can I use the output path relative to my script?
You can, but the path is resolved from the process working directory, which may differ in CI or a scheduler. An absolute path makes the destination explicit.


