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

Cast your Appium driver to Selenium’s TakesScreenshot interface and call getScreenshotAs. For a screenshot you need to keep, request OutputType.FILE and copy the returned temporary file to your test-artifact directory immediately. Driver screenshots capture the current viewport in a native app context or the window in a web context; a separate element-level call can capture one element.

Save an Appium screenshot to a permanent file

Appium exposes Selenium’s TakesScreenshot.getScreenshotAs API. A direct call returns a temporary file, not a durable test artifact: the JVM can delete that file when it exits. Copy it to your chosen path as soon as the call succeeds.

The following helper creates the destination directory, replaces a file with the same name, and returns the target path. It assumes your test has already created an Appium session and has a usable driver.

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.util.Objects;

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

public final class Screenshots {
    private Screenshots() {}

    public static Path save(WebDriver driver, Path target) throws IOException {
        Objects.requireNonNull(driver, "driver");
        Objects.requireNonNull(target, "target");

        Path absoluteTarget = target.toAbsolutePath();
        Files.createDirectories(absoluteTarget.getParent());

        File temporaryImage = ((TakesScreenshot) driver)
                .getScreenshotAs(OutputType.FILE);
        Files.copy(temporaryImage.toPath(), absoluteTarget,
                StandardCopyOption.REPLACE_EXISTING);
        return absoluteTarget;
    }

    // In a test, after the relevant screen is displayed:
    // Path saved = save(driver, Paths.get("artifacts", "login-failure.png"));
}

Add the helper to a test utility class, then call it at the point where the screen is in the state you want to inspect. The driver variable can be declared as WebDriver or as an Appium driver type, provided the actual driver supports screenshots. Paths.get("artifacts", "login-failure.png") gives the capture a stable project-relative destination; the helper resolves it to an absolute path before creating its parent directory.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Samsung Galaxy A16 4G LTE (128GB + 4GB) International Model SM-A165F/DS Factory Unlocked, 6.7", Dual SIM, 50MP Triple Camera (Case Bundle), Black
  • Please note, this device does not support E-SIM; This 4G model is compatible with all GSM networks worldwide outside of the U.S. In the US, ONLY compatible with T-Mobile and their MVNO's (Metro and Standup). It will NOT work with other CDMA carriers, and it is also not compatible with their MVNO (Visible, Xfinity Mobile, US Mobile, Cricket Wireless, etc).
  • Compatibility with certain third-party devices and accessibility accessories, including some hearing aids, may vary depending on manufacturer support, Bluetooth protocols, software compatibility, and regional firmware limitations. For additional hearing aid compatibility information, please refer to Samsung’s official support documentation.
  • Camera: 50 MP, f/1.8, (wide), 1/2.76", 0.64µm, AF | 50 MP, f/1.8, (wide), 1/2.76", 0.64µm, AF | 2 MP, f/2.4, (macro). Battery: 5000 mAh, non-removable | A power adapter is NOT included.

The replacement option makes repeated runs predictable: a new capture replaces a prior image at the same path instead of failing because the file already exists. If your test runner archives artifacts from a particular directory, choose that directory and filename convention rather than leaving the temporary source file in place.

Choose FILE, BASE64, or BYTES

OutputType determines the form in which getScreenshotAs returns the image. Choose according to what the next step in your test or reporting pipeline needs.

Rank #2
Samsung Galaxy A17 5G Smart Phone 128GB US 1 Yr Manufacturer Warranty Black
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
Output type Returned value Useful when Persistence note
FILE A temporary File A test framework or your own code will copy or archive an image file. Copy it promptly to a permanent location; the JVM deletes the temporary file at exit.
BASE64 A Base64-encoded PNG string A report or another API accepts an encoded image string. Store or transmit the string through your chosen reporting or storage mechanism.
BYTES Raw PNG bytes You need to process the image or write it using your own storage code. Write or archive the byte array before the process ends if you need to retain it.

Return Base64 for a report

String pngBase64 = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.BASE64);

The result is an encoded string, not a filesystem path. Pass it to a report integration that accepts Base64; do not treat it as though it were already a PNG file.

Write raw bytes yourself

byte[] pngBytes = ((TakesScreenshot) driver)
        .getScreenshotAs(OutputType.BYTES);
Files.write(Paths.get("artifacts", "screen.png"), pngBytes);

For this direct-write variant, create the artifacts directory first if it might not exist. Use FILE when copying a temporary image is more convenient, or BYTES when your next operation already works with byte arrays.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Tracfone Motorola Moto G 2025, 64GB, Saphire Blue (Locked to
  • Carrier: This phone is locked to Tracfone, which means this device can only be used on the Tracfone wireless network. Tracfone plan required, activating is easy, just 3 steps.
  • DISPLAY: Immersive viewing on a 6.7-inch super-bright 120Hz display with powerful stereo speakers and Bass Boost for cinematic entertainment.
  • CAMERA SYSTEM: Advanced 50MP Quad Pixel camera captures sharp, detailed photos and videos in any lighting condition
  • PERFORMANCE: Lightning-fast 5G connectivity paired with a powerful processor and RAM Boost for smooth multitasking.
  • BATTERY LIFE: Long-lasting 5000mAh battery with TurboPower charging technology delivers hours of power in minutes.

Capture the whole screen or one element

Driver screenshot: current viewport or window

Calling getScreenshotAs on the driver captures the current visible surface, not a sequence of screens. In Appium’s terms, a native iOS or Android context captures the viewport; a web context captures the window. If the screen has not reached the state you intend to document, the image will show the state present at capture time. Put the call after the navigation or interaction whose result you are checking.

Element screenshot: a particular component

Selenium defines WebElement as a TakesScreenshot subinterface, so an element can be the screenshot target when the driver and platform implementation support it. Find the element first, then call the same method on that element:

Rank #4
Samsung Galaxy A17 5G Smart Phone 128GB, US 1 Yr Manufacturer Warranty Blue
  • YOUR CONTENT, SUPER SMOOTH: The ultra-clear 6.7" FHD+ Super AMOLED display of Galaxy A17 5G helps bring your content to life, whether you're scrolling through recipes or video chatting with loved ones.¹
  • LIVE FAST. CHARGE FASTER: Focus more on the moment and less on your battery percentage with Galaxy A17 5G. Super Fast Charging powers up your battery so you can get back to life sooner.²
  • MEMORIES MADE PICTURE PERFECT: Capture every angle in stunning clarity, from wide family photos to close-ups of friends, with the triple-lens camera on Galaxy A17 5G.
  • NEED MORE STORAGE? WE HAVE YOU COVERED: With an improved 2TB of expandable storage, Galaxy A17 5G makes it easy to keep cherished photos, videos and important files readily accessible whenever you need them.³
  • BUILT TO LAST: With an improved IP54 rating, Galaxy A17 5G is even more durable than before.⁴ It’s built to resist splashes and dust and comes with a stronger yet slimmer Gorilla Glass Victus front and Glass Fiber Reinforced Polymer back.
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebElement;

WebElement panel = driver.findElement(By.id("error-panel"));
File temporaryElementImage = ((TakesScreenshot) panel)
        .getScreenshotAs(OutputType.FILE);
Files.copy(temporaryElementImage.toPath(),
        Paths.get("artifacts", "error-panel.png"),
        StandardCopyOption.REPLACE_EXISTING);

As with a driver capture, copy the temporary file promptly. This is useful when a report needs evidence focused on a component rather than the complete viewport. Element capture is not a workaround for an unsupported driver screenshot: if the implementation does not support the operation, changing the target to an element will not guarantee success.

Capture at the right point in a test

A screenshot is a snapshot of the display when the command runs. For useful failure evidence, call the helper close to the assertion or interaction under investigation, while the relevant screen is still displayed and before cleanup ends the session or changes the app state.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
Samsung Galaxy A16 5G 128GB Cell Phone, Unlocked Android Smartphone, Large AMOLED Display, Durable Design, Super Fast Charging, Expandable Storage, US Version, 2025, Blue Black (Renewed)
  • Charger NOT Included, 6.7" Super AMOLED FHD+, 90Hz Refresh Rate, 385 ppi, 800 nits (HBM), 1080x2340px, 5000mAh Battery
  • 128GB, 4GB RAM, microSDXC, Exynos 1330 (5nm), Octa-Core, Mali-G68 MP2 or Mali-G57 MC2 GPU
  • Rear Camera: 50MP, f/1.8 (wide) + 5MP, f/2.2 (ultrawide) + 2MP, f/2.4 (macro), LED flash, panorama, HDR; Front Camera: 13MP, f/2.0, Android 14, up to 6 major Android upgrades, One UI 6.1
  • 3G: HSDPA 850/900/1700(AWS)/1900/2100; 4G LTE: 1/2/3/4/5/7/12/13/14/20/25/26/28/29/30/38/39/40/41/48/66/71, 5G: 2/5/25/41/66/71/77/78 SA/NSA/Sub6/mmWave - Nano-SIM + eSIM
  • US Model – Global Connectivity – Compatible with Most GSM Carriers like T-Mobile, AT&T, MetroPCS, etc. Will Also work with CDMA Carriers Such as Verizon, Straight Talk.
  1. Drive the app to the screen or condition you want to inspect.
  2. Call getScreenshotAs on the driver for the viewport/window, or on a supported element for a focused image.
  3. If using FILE, copy the returned temporary file immediately into the test’s artifact directory.
  4. Use a distinctive filename or a per-test directory if several captures could otherwise overwrite each other.
  5. Have your existing test-reporting or CI artifact process retain the saved file if it must be available after the run.

Screenshot capture does not itself make a test wait for a particular app state or archive its files in a report. Coordinate the call with the state checks and artifact handling already used by your test suite.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Why getScreenshotAs can fail

Selenium documents WebDriverException for screenshot failures and UnsupportedOperationException when an implementation does not support screenshots. Appium also cautions that platform security restrictions can block capture. Check the exception and the active test context rather than assuming every failure is a bad output path.

Symptom Likely cause What to check
ClassCastException at the cast to TakesScreenshot The actual driver object does not implement the screenshot interface. Confirm the driver instance and platform implementation support the screenshot API before casting.
UnsupportedOperationException The active driver or target does not support this screenshot operation. Check support for the driver, platform, context, and whether an element-level operation is supported.
WebDriverException from the screenshot call The capture command failed; possible causes include device state, context, or platform restrictions. Check that the session is active, the device is responsive, and the app is in the expected context; inspect the platform-specific failure details.
A file is missing after the test process exits The code retained the temporary FILE result rather than copying it. Copy it to the artifact path immediately after capture and ensure the reporting job collects that path.
A screenshot has zero dimensions or capture is rejected The platform cannot provide a valid image for the current surface. Check device/display state and the surface being captured. UiAutomator2’s screenshot implementation rejects zero-dimension images.
An Android screen is blank or capture is blocked The app may protect its surface using Android’s FLAG_SECURE. Check whether the app or platform security policy intentionally prevents screenshots. A client-side save-path change cannot override that policy.

Keep artifacts reliable and manageable

  • Persist immediately: a temporary file is a handoff from the driver, not an archive. Copy or otherwise store it during the test.
  • Make paths deterministic: use a known artifact directory, and ensure your CI or test runner collects it.
  • Avoid accidental overwrites: use distinct names for multiple captures, or deliberately replace a known filename when only the latest image matters.
  • Capture at a meaningful point: an image taken before the app reaches the target state may be valid but unhelpful evidence.
  • Use the right output representation: choose a file for artifact collection, Base64 for a report that takes encoded strings, or bytes for custom processing/storage.

Screenshot capture adds a remote-driver operation and image data handling to the test flow. The material available here does not establish a general capture-time or image-size figure, so avoid using an assumed duration as a test timeout. If screenshot capture is part of failure handling, keep its error handling from obscuring the original test failure.

Or skip the browser setup

Appium Java is for capturing screens from an app under test; ScreenshotNeo is a separate option for capturing a website from a URL, not a replacement for an Appium device screenshot. Its one-request API returns an image or PDF, and the parameter names used by other screenshot APIs also work. See the ScreenshotNeo API documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
  • Before capture, it accepts cookie/consent banners like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off.
  • Bot checks, CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed; response headers report the page verdict and billing status.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf for Claude, Cursor, and other MCP clients.
  • The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.

For URL-based website captures, visit ScreenshotNeo. Sign up for 1,000 free screenshots a month with no card.

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.