Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › Chrome DevTools Protocol

How to Capture Full-Page Screenshots of Indian Railway Booking Pages with Selenium

By Freedom251 Team · · 5 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

For a Chrome page you own or are authorized to test, use Selenium’s Chrome DevTools Protocol (CDP) command Page.captureScreenshot with captureBeyondViewport: true. Measure the document, decode Chrome’s Base64 image data, and check the resulting PNG. Do not use Selenium to automate the live IRCTC booking service: IRCTC’s online booking terms say automation and scripting software are strictly prohibited.

Why does Selenium only screenshot the visible page?

Selenium’s standard screenshot methods capture the current browsing context; they do not promise to expand the capture to the entire document. That is appropriate for checking what a user sees in the current viewport, but it is different from a full-document screenshot. Chrome’s CDP provides a separate capture command with a captureBeyondViewport option, documented as false by default. Set it to true when you need a capture extending beyond the viewport.

As an Amazon Associate I earn from qualifying purchases.

The code below is for an authorized Chrome test or staging page, not for operating or capturing a live IRCTC booking flow with automation. Use the browser and driver versions supported by your project, since CDP protocol details and Selenium’s wrapper can vary by release. See Selenium’s WebDriver documentation and the Chrome DevTools Protocol Page documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to capture a full-page screenshot with Selenium in Chrome

Python example

This example obtains the page’s content dimensions, asks CDP for a PNG beyond the viewport, and writes Chrome’s Base64 response to full-page.png. Replace the example address with a page you are authorized to automate. Add a page-specific readiness condition before measuring if your application renders content asynchronously.

import base64
from selenium import webdriver

# Use only for a page you own or are authorized to automate.
driver = webdriver.Chrome()
try:
    driver.get("https://example.test/page")

    # Replace this with a condition for the application content your test needs.
    # driver.implicitly_wait(...) is not a substitute for a page-specific readiness check.

    metrics = driver.execute_cdp_cmd("Page.getLayoutMetrics", {})
    content = metrics.get("cssContentSize") or metrics.get("contentSize")
    if not content:
        raise RuntimeError("Chrome did not return document content dimensions")

    result = driver.execute_cdp_cmd(
        "Page.captureScreenshot",
        {
            "format": "png",
            "captureBeyondViewport": True,
            "fromSurface": True,
            "clip": {
                "x": 0,
                "y": 0,
                "width": content["width"],
                "height": content["height"],
                "scale": 1,
            },
        },
    )
    with open("full-page.png", "wb") as image_file:
        image_file.write(base64.b64decode(result["data"]))
finally:
    driver.quit()

The protocol returns screenshot data as Base64; the script decodes it to PNG bytes. It prefers cssContentSize when available and falls back to contentSize. If neither field is returned, it stops with an explicit error rather than silently saving an incomplete image. The fromSurface parameter is part of the protocol, but validate behavior with your installed Chrome release.

Wait for the content the test actually needs

A completed navigation does not necessarily mean an application’s asynchronous content is ready. Wait for a relevant element or state before asking for dimensions. If the page uses lazy loading, scroll through it in your authorized test context and wait for the required content to appear; the screenshot command itself does not guarantee that lazy or interaction-dependent content has loaded.

Inspect the saved image

Open full-page.png and check the top and bottom, tables, status text, and any dynamic content the test is meant to cover. A successful CDP response does not establish that all application content rendered correctly.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Keep Selenium automation off the live IRCTC booking flow

IRCTC’s online booking terms state: “Use of automation software and/or Scripting Software is strictly prohibited.” The technical method above is therefore for a local fixture, approved staging page, or another site where you have permission—not for automating live ticket searches, bookings, or account actions.

As official context, a Ministry of Railways release published by the Press Information Bureau on 4 June 2025 reported 2.5 crore suspected user IDs deactivated, 31,814 tickets booked in a single minute on 22 May 2025, and 82.57 lakh average daily logins in FY 2024–25. These are ministry-reported figures for those stated periods, not independent measurements or a prediction about an individual account. The release describes anti-bot enforcement; the direct restriction on automation is in IRCTC’s terms.

For a real booking, use only capture methods permitted by the current IRCTC terms and retain the official booking record where relevant. A screenshot is not itself a ticket or reservation record.

When a full-page PNG is not the right output

Very tall pages can create large raster images or encounter browser and device limits. For a readable record, capture logical sections or use PDF output rather than forcing the entire page into one enormous bitmap. Chrome documents headless screenshot and PDF options, and notes that full-page capture takes more than a basic screenshot flag; see Chrome’s headless documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshooting full-page Selenium captures

  • Only the visible area appears: Confirm that you are invoking Chrome CDP’s Page.captureScreenshot with captureBeyondViewport: true. A normal WebDriver screenshot is a different operation.
  • The bottom is missing or blank: Check the dimensions returned by Page.getLayoutMetrics, wait for asynchronous application content, and account for lazy loading before capturing.
  • Dynamic content is absent: Wait for the specific element or state your test needs. Do not assume that capture causes scripts, scrolling, or interaction-dependent content to run.
  • Sticky headers or overlays obscure content: The image represents the rendered page state. Prepare a suitable authorized test fixture or page state; do not alter or automate a live booking flow in conflict with IRCTC terms.
  • The image is too tall or unwieldy: Capture sections separately or choose PDF when the goal is a readable record.
  • The target is a live IRCTC page: Stop rather than applying Selenium automation; the published terms prohibit automation and scripting software.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. For an authorized page, a single request can return an image; see the API documentation. This does not make automation of the live IRCTC booking service permissible.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.test/page -o shot.webp

ScreenshotNeo accepts cookie or consent banners and removes known consent platforms, newsletter popups, and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and the response indicates the page verdict and billing status. Its MCP server offers screenshot and 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 shots.

Sign up for 1,000 free screenshots a month—no card required.

Frequently Asked Questions

Can Selenium’s regular screenshot method save a full document?

It captures the current browsing context and does not promise a full-document image. In authorized Chrome automation, use CDP’s capture command for beyond-viewport output.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Does a full-page screenshot include every lazy-loaded item automatically?

No. Load and verify the content required by your test before capture; a screenshot command does not guarantee lazy or interaction-dependent content is present.

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.

Chrome DevTools Protocolfull-page screenshotsIRCTCSeleniumweb testing

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.