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

Some links on this page are affiliate links: if you buy through them we may earn a commission, at no extra cost to you.

Use Selenium’s screenshot API on the current browsing context, or call the corresponding element method after locating an element. Python saves directly with driver.save_screenshot(); Java uses TakesScreenshot and copies the returned file; C# uses ITakesScreenshot and SaveAsFile(). These documented calls capture the current context or an element—not a guaranteed full page in every browser and driver.

Python: save the current Selenium window as PNG

The Selenium Python binding documents save_screenshot() for writing the current window to a PNG path. It returns False when an I/O error prevents saving, so check the result when a failed write matters.

from selenium import webdriver

driver = webdriver.Chrome()
try:
    driver.get("https://example.com")
    saved = driver.save_screenshot("screenshot.png")
    if not saved:
        raise OSError("Could not save screenshot")
finally:
    driver.quit()

See the Selenium Python WebDriver API for save_screenshot() and get_screenshot_as_file(). Both write PNG files and return False on an I/O error; use a filename ending in .png.

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

Get PNG bytes or base64 instead of writing a file

  • driver.get_screenshot_as_png() returns PNG bytes, useful when your code uploads or processes the image itself.
  • driver.get_screenshot_as_base64() returns a base64-encoded string suitable for embedding in HTML.

Capture one element in Python

Locate the element, then call its screenshot method:

element = driver.find_element("css selector", "#checkout")
element.screenshot("checkout.png")

The element screenshot workflow is shown in Selenium’s official browser windows documentation.

Java: use TakesScreenshot and copy the returned file

In Java, cast the driver to TakesScreenshot, request OutputType.FILE, and copy that temporary file to your destination.

WebDriver driver = new ChromeDriver();
try {
    driver.get("https://example.com");
    File screenshot = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.FILE);
    FileUtils.copyFile(screenshot, new File("screenshot.png"));
} finally {
    driver.quit();
}

This is the pattern in Selenium’s official windows and tabs guide. Your project must provide the file-copy utility represented by FileUtils; the Selenium-specific operation is getScreenshotAs(OutputType.FILE).

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

Capture a Java WebElement

WebElement panel = driver.findElement(By.cssSelector("#checkout"));
File elementFile = panel.getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(elementFile, new File("checkout.png"));

The element is located first, then its own getScreenshotAs(OutputType.FILE) method is used.

C#: save a Screenshot object as PNG

The C# binding casts the driver to ITakesScreenshot, obtains a Screenshot, and saves it with an explicit image format.

var driver = new ChromeDriver();
try
{
    driver.Navigate().GoToUrl("https://example.com");
    var screenshot = ((ITakesScreenshot)driver).GetScreenshot();
    screenshot.SaveAsFile("screenshot.png", ScreenshotImageFormat.Png);
}
finally
{
    driver.Quit();
}

Selenium’s documented format values include Bmp, Gif, Jpeg, Png, and Tiff; the example chooses PNG. The API pattern appears in the official guide.

Capture an element in C#

var panel = driver.FindElement(By.CssSelector("#checkout"));
var elementShot = ((ITakesScreenshot)panel).GetScreenshot();
elementShot.SaveAsFile("checkout.png", ScreenshotImageFormat.Png);

Current-context screenshot versus full-page capture

These APIs demonstrate a screenshot of the current browsing context or a selected element. Do not label the result “full page” without confirming the exact browser, driver, and binding behavior you deploy. The reviewed Selenium documentation does not establish one universal full-page guarantee across implementations. If you need a whole document, verify the output in each target environment and consider a capture service that explicitly supports full-page rendering.

Free tools Windows power users keep installed

One-click scans. No signup required.

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

Common save failures and checks

  • No file appears: verify the destination directory exists and that the test process can write to it. In Python, check the Boolean return value.
  • Unexpected image area: confirm whether you called the driver or an element. A driver call captures the current context; an element call crops to that element.
  • Different results across browsers: treat full-page behavior as implementation-specific and test every browser/driver combination you support.
  • Browser left running after an error: keep quit() in a finally block, as in the examples.
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 hosted screenshot API and MCP server. One GET request returns a PNG, JPEG, WebP, or PDF, so you do not need to manage Selenium, browser binaries, or drivers for a straightforward URL capture.

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

See the ScreenshotNeo documentation for request options. Before capture it accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and each response reports the result in X-Page-Verdict and X-Billed headers. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients.

The Free plan includes 1,000 screenshots per month with no card. Paid plans start at $5 for 3,000 shots; every feature is available on every plan. Sign up for the free plan.

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.

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.