How to Fix Blank Google Search Screenshots in Selenium
Diagnose whether Google failed to load or Selenium captured the wrong state, then fix the browser, driver, Headless, or runtime issue.
A blank Google Search screenshot in Selenium does not have one universal fix. First check whether Chrome actually loaded the expected page: record the current URL, title, page text, browser and driver versions, and screenshot dimensions. If the page content is missing, investigate navigation or the runtime; if the page content exists but the image is blank, investigate rendering and capture state.
This guide uses Java, the language shown in Selenium’s examples, and includes runnable diagnostic examples in Python, Node.js, and cURL for comparison. Selenium captures the current browsing context, so the key is to verify what that context contains before changing screenshot code. See Selenium’s Chrome WebDriver documentation and window and tab documentation.
1. Save evidence from the failing run
Before changing flags or versions, capture enough evidence to separate a page-loading problem from an image-capture problem. Record the exact runtime (local machine, CI, or container), operating system, Selenium version, Chrome version, ChromeDriver version, whether Headless is enabled, requested URL, final URL, page title, and a short sample of visible text. Keep the screenshot artifact and browser logs too.
ChromeDriver is a separate executable that Selenium uses to control Chrome. Check the versions from the same environment and executable paths used by the test; a locally installed browser version may not be the one CI launches.
2. Check page state before saving the screenshot
Wait for a condition that represents the content your test needs, then inspect URL, title, and page text. A navigation call returning does not by itself prove that the expected visible results have rendered. This is a practical diagnostic, not a Google-specific Selenium guarantee.
Java diagnostic example
import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class GoogleScreenshotDiagnostic {
public static void main(String[] args) throws Exception {
ChromeOptions options = new ChromeOptions();
// Add options.addArguments("--headless") to compare Headless mode.
WebDriver driver = new ChromeDriver(options);
try {
driver.manage().window().setSize(new org.openqa.selenium.Dimension(1365, 900));
driver.get("https://www.google.com/search?q=selenium+webdriver");
new WebDriverWait(driver, Duration.ofSeconds(20)).until(d ->
!d.findElement(By.tagName("body")).getText().isBlank());
System.out.println("URL: " + driver.getCurrentUrl());
System.out.println("Title: " + driver.getTitle());
String text = driver.findElement(By.tagName("body")).getText();
System.out.println("Body text sample: " + text.substring(0, Math.min(500, text.length())));
byte[] png = ((org.openqa.selenium.TakesScreenshot) driver)
.getScreenshotAs(OutputType.BYTES);
if (png.length == 0) throw new IllegalStateException("Screenshot is empty");
Files.write(Path.of("google.png"), png);
System.out.println("Wrote google.png (" + png.length + " bytes)");
} finally {
driver.quit();
}
}
}
The wait above confirms that the body has some text, not that Google results specifically are present. For a stable automated test, wait for a page-specific condition appropriate to the outcome you expect, while recognizing that page markup can change. If text is absent or the URL is unexpected, troubleshoot loading before focusing on the PNG write.
Python diagnostic example
from pathlib import Path
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
options = webdriver.ChromeOptions()
# Uncomment to compare Headless with a visible run:
# options.add_argument("--headless")
options.add_argument("--window-size=1365,900")
driver = webdriver.Chrome(options=options)
try:
driver.get("https://www.google.com/search?q=selenium+webdriver")
WebDriverWait(driver, 20).until(
lambda d: d.find_element(By.TAG_NAME, "body").text.strip()
)
body = driver.find_element(By.TAG_NAME, "body").text
print("URL:", driver.current_url)
print("Title:", driver.title)
print("Body text sample:", body[:500])
if not driver.save_screenshot("google.png"):
raise RuntimeError("WebDriver reported that screenshot saving failed")
if Path("google.png").stat().st_size == 0:
raise RuntimeError("Screenshot file is empty")
finally:
driver.quit()
Node.js diagnostic example
const { Builder, By, until } = require('selenium-webdriver');
const chrome = require('selenium-webdriver/chrome');
const fs = require('node:fs');
(async () => {
const options = new chrome.Options().windowSize({ width: 1365, height: 900 });
// Compare Headless by adding: options.addArguments('--headless');
const driver = await new Builder().forBrowser('chrome').setChromeOptions(options).build();
try {
await driver.get('https://www.google.com/search?q=selenium+webdriver');
await driver.wait(async () => {
const body = await driver.findElement(By.css('body')).getText();
return body.trim().length > 0;
}, 20000);
console.log('URL:', await driver.getCurrentUrl());
console.log('Title:', await driver.getTitle());
console.log('Body text sample:', (await driver.findElement(By.css('body')).getText()).slice(0, 500));
const pngBase64 = await driver.takeScreenshot();
const png = Buffer.from(pngBase64, 'base64');
if (png.length === 0) throw new Error('Screenshot is empty');
fs.writeFileSync('google.png', png);
} finally {
await driver.quit();
}
})().catch(err => { console.error(err); process.exitCode = 1; });
3. Align Chrome and ChromeDriver versions
Check the actual Chrome and ChromeDriver versions used by the run. Selenium’s Chrome documentation says Selenium 4 is compatible with Chrome 75 and later, and that Chrome and ChromeDriver must match at the major-version level. Use the version output from the same CI job or container that runs the test, and confirm Selenium is selecting the binary you inspected.
google-chrome --version
chromedriver --version
On some systems the browser binary has a different executable name or path. In that case, inspect the configured binary path and invoke that exact file to get its version. Avoid changing several versions and flags together: change one variable, rerun the same URL and readiness check, and compare the evidence.
4. Compare Headless and visible Chrome
Run the same script with Headless enabled and disabled while keeping URL, browser and driver versions, viewport, and wait condition constant. Chrome documents Selenium Headless configuration with the --headless option. This comparison is diagnostic, not a guaranteed fix.
- Visible works, Headless is blank: investigate Headless configuration, browser-version behavior, and the environment’s display or launch setup.
- Both are blank: look first at the final URL, page text, navigation, and runtime logs.
- Page text exists but the screenshot is blank: check the active tab/window, viewport dimensions, screenshot file, and browser rendering behavior.
A Selenium issue records a report of a blank white window after a Chrome 129 update, but that report does not establish a general cause or a current workaround. Treat issue reports as leads to compare against your exact versions, not instructions to apply blindly: Selenium issue 14514.
5. Reproduce inside the same CI or container
If the failure happens only in a background service, CI runner, or container, try launching Chrome directly from that same environment. ChromeDriver’s troubleshooting guidance recommends checking whether Chrome can start directly and whether the problem also occurs in the testing environment. If direct launch fails, investigate the browser binary and runtime environment before Selenium’s screenshot call. If direct launch succeeds, compare the binary, flags, profile, and logs used by WebDriver. That distinction is an inference from the isolation step, not a guaranteed diagnosis.
Keep the reproduction controlled: same URL, same browser and driver, same viewport, and same runtime. Save Chrome’s startup output and ChromeDriver logs so a failed launch is not mistaken for an empty screenshot.
6. Verify the screenshot artifact
Selenium’s screenshot API captures the current browsing context. Confirm the correct window or tab is active, the capture method returned data, the file exists, and its dimensions are nonzero. Check the image itself rather than assuming a successful file write means the page rendered correctly.
Chrome’s Headless documentation also shows direct command-line capture with an explicit window size. A direct Chrome capture can help distinguish browser screenshot behavior from WebDriver orchestration; it is a diagnostic comparison and does not replace checking page state.
cURL: direct Chrome Headless comparison
This invokes Chrome itself, not Selenium. Adjust the Chrome executable path for the environment. Chrome’s documented Headless flags include --headless, --screenshot, and --window-size.
google-chrome --headless --screenshot=google.png --window-size=1365,900 'https://www.google.com/search?q=selenium+webdriver'
7. Common errors and fixes
| Symptom | Likely area to inspect | Next step |
|---|---|---|
| White image and empty body text | The page did not reach the expected content state | Check final URL, title, navigation and browser logs before modifying screenshot code. |
| White image but expected body text is present | Rendering, active context, viewport, or capture behavior | Confirm active window, set an explicit viewport, inspect the PNG dimensions, and compare visible with Headless. |
| Chrome fails to start in CI | Browser binary or environment launch issue | Try launching that Chrome binary directly in the same environment; preserve startup and driver logs. |
| ChromeDriver session creation fails or behaves differently across machines | Browser/driver selection or major-version mismatch | Print both versions in the failing job and verify their major versions match. |
| Screenshot file is missing, zero bytes, or unreadable | File output or screenshot response handling | Check the save result, write permissions and file size; ensure a returned Base64 screenshot is decoded correctly in Node.js. |
| Only Headless produces the blank result | Headless-specific configuration or version behavior | Repeat the controlled visible/Headless comparison and investigate the exact versions and launch logs. |
The sources reviewed do not establish a Google-specific cause such as consent prompts, network policy, anti-automation behavior, localization, or account state. Check these possibilities only when the observed URL, page text, or logs point in that direction; do not assume one is responsible from a blank PNG alone.
8. Performance, reliability, and cost
For reliable diagnosis, prefer explicit page conditions over arbitrary sleeps, and keep the viewport and versions fixed while comparing runs. An explicit wait can avoid capturing too early without forcing every run to pause for a long fixed delay. There is no benchmark in the cited material for a universal wait duration or capture speed, so choose a timeout suitable for the environment and log when it expires.
Retries can help distinguish transient navigation failures from repeatable rendering defects, but record each attempt’s final URL and page state. Do not treat a retry that produced a file as success unless the expected content and image are both present. Selenium’s browser setup also carries the maintenance cost of keeping Chrome, ChromeDriver, runtime dependencies, and CI configuration aligned. This guide’s sources provide no numerical Selenium cost or performance comparison.
Or skip the browser setup
If the goal is a clean screenshot rather than debugging a Selenium environment, ScreenshotNeo provides a website screenshot API and MCP server. One GET request returns an image or PDF. See the API documentation.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://www.google.com/search?q=selenium+webdriver -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://www.google.com/search?q=selenium+webdriver"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://www.google.com/search?q=selenium+webdriver' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);
if (!res.ok) throw new Error(`Screenshot request failed: ${res.status}`);
const fs = require('node:fs');
fs.writeFileSync('shot.webp', Buffer.from(await res.arrayBuffer()));
ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture; those steps can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers report the page verdict and billing status. AI agents can use its MCP 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. All features are available on every plan.
Sign up for ScreenshotNeo free: 1,000 screenshots a month, no card required.
FAQ
Why is my Selenium screenshot blank when the page title looks correct?
A title alone does not prove that the visible content you need has rendered. Inspect page text or a page-specific condition, then compare that state with the image.
Should I add --no-sandbox to fix it?
The reviewed sources do not establish that flag as a general fix for blank Google screenshots. Diagnose launch and page state in the failing environment and apply flags only when evidence supports them.
Does a historical Chrome issue prove this is a Chrome regression?
No. An individual issue report is useful context, but the exact versions and reproduction determine whether it is relevant to your run.
What details help someone diagnose my blank screenshot?
Provide the script, Selenium/Chrome/ChromeDriver versions, operating system and runtime, Headless setting, final URL, title, relevant page text, logs, and the screenshot artifact.


