ScreenshotNeo

BlogHow-to

Fix Java Selenium Screenshots with a Missing or Cut-Off Page

Diagnose missing or cut-off Selenium screenshots in Java. Choose the right capture scope, wait for the page state you need, and check browser support.

By the ScreenshotNeo team4 October 20268 min read

A cut-off Selenium screenshot usually has one of two causes: the driver captured only the current browsing context, or the page had not finished rendering the content you expected. First identify whether you need a screenshot of the visible browser, one element, or the whole document. Then choose a capture method your browser and driver support, and wait for the specific content to be ready.

1. Identify what is missing

“Missing” can mean different things, and each symptom points to a different fix:

Symptom First thing to check
Content below the viewport is absent Whether the method captures the full document or only the current browsing context.
A chart, table, or component is clipped Whether to capture the element directly, and whether it has finished rendering.
The image is blank or shows old content Whether the application finished loading the state you wanted before capture.
The captured region has unexpected dimensions The browser window or viewport size, and the screenshot target.

Selenium’s standard driver screenshot call is TakesScreenshot#getScreenshotAs. The API describes screenshots in terms of the current browsing context; do not assume the call always produces a stitched image of the entire document. Selenium’s Java example also documents screenshots of individual elements, which are a separate target. See the Selenium full-page screenshot API and its WebDriver documentation.

2. Capture the current browsing context in Java

Use this standard call when the desired output is the screenshot provided for the current browser context. It does not promise full-document capture across browsers.

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ViewportScreenshot {
    public static void main(String[] args) throws IOException {
        WebDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");

            File screenshot = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);
            Files.copy(screenshot.toPath(), Path.of("screenshot.png"));
        } finally {
            driver.quit();
        }
    }
}

The imports and capture call are the important part; configure the browser driver according to your project and Selenium setup. The output file is named screenshot.png here, but use the format and extension appropriate to your output. Selenium’s Firefox browser documentation describes Firefox-specific capabilities and version considerations.

3. Capture a full page with the documented Firefox API

Selenium documents FirefoxDriver as implementing HasFullPageScreenshot. Use its full-page method when your actual Firefox driver supports that interface and your execution setup exposes the command:

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.HasFullPageScreenshot;

public class FirefoxFullPageScreenshot {
    public static void main(String[] args) throws IOException {
        FirefoxDriver driver = new FirefoxDriver();
        try {
            driver.get("https://example.com");

            File screenshot = ((HasFullPageScreenshot) driver)
                .getFullPageScreenshotAs(OutputType.FILE);
            Files.copy(screenshot.toPath(), Path.of("full-page.png"));
        } finally {
            driver.quit();
        }
    }
}

This is a Firefox-specific API. Do not assume the cast or command works with Chrome, every RemoteWebDriver, or every Grid setup. Check the Selenium, Firefox, geckodriver, and remote execution versions in the environment where the test runs. Selenium’s Firefox documentation notes Firefox version requirements for Selenium 4 and recommends a current geckodriver; verify compatibility for your actual versions.

4. Capture one element instead of the page

If only a specific component is needed, use an element screenshot. This changes the capture target; it does not solve content that has not rendered yet.

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import java.time.Duration;

public class ElementScreenshot {
    public static void main(String[] args) throws IOException {
        ChromeDriver driver = new ChromeDriver();
        try {
            driver.get("https://example.com");

            WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
            WebElement chart = wait.until(
                ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#chart"))
            );

            File screenshot = chart.getScreenshotAs(OutputType.FILE);
            Files.copy(screenshot.toPath(), Path.of("chart.png"));
        } finally {
            driver.quit();
        }
    }
}

Replace #chart with a selector that identifies your target. If the element appears before its data is ready, wait for a page-specific completion marker or condition as well.

5. Wait for the content you intend to capture

A completed navigation does not necessarily mean a JavaScript application has finished populating the page. Selenium’s waiting guide explains that document.readyState concerns assets defined in the HTML; JavaScript can still change the page afterward. Wait for a meaningful condition such as the visibility of the target element or the appearance of a final content marker. See Selenium’s Waiting Strategies.

import java.time.Duration;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
wait.until(ExpectedConditions.visibilityOfElementLocated(
    By.cssSelector("[data-test='report-ready']")
));

// Capture only after the application-specific ready condition is met.

Choose a condition that reflects the content in the screenshot. For a report, that might mean a final status marker is visible; for a chart, it could be a rendered chart element. A fixed sleep can add time without proving that the page is ready.

6. Treat lazy-loaded content as a separate behavior

Some pages load images or other content only when a user scrolls. Initial navigation and a full-page capture method do not establish that every application-specific, scroll-triggered item has loaded. Check whether the content is triggered by scrolling, whether it sits inside a nested scrollable region, and what state indicates it has loaded. If needed, scroll through the relevant area and wait for that condition before capture. The exact scrolling approach depends on the page; the cited Selenium documentation does not establish one universal recipe for every lazy-loading implementation.

7. Understand page-load strategy

Selenium’s page-load strategies change when navigation returns:

Strategy Navigation behavior Screenshot implication
normal Waits for the complete document state. Does not make a viewport capture full-page or prove application content is ready.
eager Returns when the document is interactive. Use an explicit wait for the content needed before capture.
none Does not block navigation on document readiness. Use an explicit wait for the desired page state.

These settings affect navigation timing, not screenshot dimensions or stitching. Review Selenium’s Browser Options and Waiting Strategies documentation when configuring them.

8. Troubleshooting checklist

Problem Likely cause What to do
Screenshot ends at the viewport The selected call captured the current browsing context, not the full document. Use a full-page API documented for your browser, such as Firefox’s HasFullPageScreenshot when supported. Confirm the actual driver and execution mode.
Full-page cast fails or command is unavailable The driver object or remote execution setup does not support the Firefox-specific interface. Check the runtime driver type, Selenium and browser versions, geckodriver, and Grid/remote setup. Do not apply the Firefox API to another browser by assumption.
Screenshot is blank or stale Capture ran before the application rendered the desired state. Wait for a specific visible element or final state marker. A completed document load alone may not be enough.
Images or sections are missing below the fold They may load only after scroll, or the screenshot method may not capture the full document. Check the page’s lazy-loading behavior, scroll the relevant region if required, wait for the loaded state, and verify the capture scope.
Only one component is clipped or absent The wrong target was captured, or the component was not ready. Capture the element directly and wait for its visibility and application-specific completion state.
Behavior differs locally and on Grid Remote execution may expose different browser commands or capabilities. Record Selenium, browser, driver, and local/remote versions, then check the documented support for that exact setup.

9. Performance, reliability, and cost considerations

A full-page capture can involve more content than a viewport or element screenshot, so use the smallest scope that answers your test or documentation need. Wait for a condition tied to the page state rather than adding a long fixed delay to every capture. For repeatable diagnosis, record the browser, driver, Selenium versions, local or remote execution mode, capture method, and the page condition used before capture.

The cited Selenium sources do not provide a cross-browser performance benchmark or a universal guarantee for long pages, lazy loading, or remote full-page capture. Validate those behaviors in the browser and execution environment you actually use. Cost depends on your browser infrastructure and test execution; this guidance does not assume a particular hosting price.

10. Or skip the browser setup

ScreenshotNeo is a website screenshot API and MCP server. One GET request can return a PNG, JPEG, WebP, or PDF. Its API documentation covers the 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}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
await Bun.write('shot.webp', res);
  • Cookie banners are accepted and removed before capture; known consent platforms, newsletter popups, and chat widgets can be removed.
  • Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed. Responses include X-Page-Verdict and X-Billed headers.
  • An MCP server gives AI agents tools to take screenshots, get page information, and capture PDFs.
  • The free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 screenshots.

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

11. FAQ

Does TakesScreenshot always take a full-page screenshot?

No. Treat it as a screenshot of the current browsing context unless your browser and driver document the full-page behavior you need.

Can I use Selenium’s Firefox full-page method with Chrome?

The documented HasFullPageScreenshot API is Firefox-specific. Check the API and capabilities for the browser and driver you run.

Is document.readyState == "complete" enough?

Not necessarily. A JavaScript application may still be changing the page. Wait for a condition that represents the content you need.

Will scrolling fix every missing section?

No universal scroll-and-capture behavior is established here. First determine whether the page loads content on scroll and whether your chosen screenshot method captures the intended scope.