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

Use Appium’s UiAutomator2 driver to create a Python WebDriver session for the Android emulator, then call Selenium’s screenshot method: driver.save_screenshot("screenshot.png"). The file is a PNG of the current WebDriver-controlled Android viewport. It is not automatically a capture of the host desktop or the emulator window borders.

What this method captures

Selenium’s Python WebDriver API captures the current window exposed by the active WebDriver session. In an Android automation session, Appium supplies that session and UiAutomator2 communicates with the emulator. Appium documents its native screenshot command as capturing the native Android viewport; in a web context, the target is the browser window or viewport.

That distinction matters:

  • App or device screenshot: use Appium with UiAutomator2 and Selenium’s screenshot API.
  • Host-desktop screenshot: use a desktop capture utility separately if you need emulator borders, the operating-system taskbar, or other windows.

The Selenium API documentation for version 4.49.0 defines save_screenshot(filename) as saving the current window to PNG and returning a Boolean. It also exposes get_screenshot_as_png() for bytes and get_screenshot_as_base64() for a Base64 string.

Prerequisites

Install the components that match your operating system and the versions of Appium, the UiAutomator2 driver, Android, and Selenium you intend to use. The UiAutomator2 driver documentation lists these version-sensitive requirements:

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.
  • Android SDK, including SDK Platform Tools and an emulator system image.
  • An Android SDK path configured in your environment.
  • A Java Development Kit.
  • Appium Server and the Appium UiAutomator2 driver.
  • A created Android Virtual Device (AVD), unless you connect a physical device instead.
  • Python, Selenium, and the Appium Python Client.

Because driver requirements change, check the current UiAutomator2 driver documentation for the release installed on your machine. The examples below intentionally leave your local AVD name, package, activity, and software versions as variables.

Install the Python clients

Create and activate a virtual environment, then install Selenium and the Appium client:

python -m venv .venv
# macOS/Linux
source .venv/bin/activate
# Windows PowerShell
# .venvScriptsActivate.ps1

python -m pip install --upgrade pip
python -m pip install selenium Appium-Python-Client

Start Appium separately. With a standard installation, the local server listens at http://127.0.0.1:4723. Confirm that the server is running before creating the session.

Capture a native Android app screenshot

Set the UiAutomator2 options, create a remote session, interact with the app until the desired screen is visible, and save the image to a writable path:

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

from appium import webdriver
from appium.options.android import UiAutomator2Options

options = UiAutomator2Options()
options.platform_name = "Android"
options.automation_name = "UiAutomator2"
options.avd = "YOUR_AVD_NAME"
options.app_package = "your.app.package"
options.app_activity = "your.app.Activity"

# Appium must already be running at this URL.
driver = webdriver.Remote(
    command_executor="http://127.0.0.1:4723",
    options=options,
)

try:
    # Perform navigation or test actions here.
    output = Path("screenshot.png")
    ok = driver.save_screenshot(str(output))
    if not ok:
        raise IOError(f"Could not write {output}")
    print(f"Saved {output.resolve()}")
finally:
    driver.quit()

The avd capability selects the named emulator. UiAutomator2 can launch that AVD when it is not already running, subject to the driver’s current requirements. If your emulator is already started and identified through Android Debug Bridge, configure the device identity as appropriate for your environment instead of relying on an AVD launch.

Use screenshot bytes

When you need to upload an image, process it in memory, or avoid a temporary file, use the byte-returning method:

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.
png_bytes = driver.get_screenshot_as_png()
with open("screenshot.png", "wb") as image_file:
    image_file.write(png_bytes)

For an API response or HTML embedding, driver.get_screenshot_as_base64() returns the encoded image data. The result still represents the WebDriver-controlled viewport, not the host display.

Capture Chrome running in the emulator

For mobile web testing, do not set an app package and activity. Appium’s Android guide uses an empty app capability and a Chrome browser capability:

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.
from appium import webdriver
from appium.options.android import UiAutomator2Options

options = UiAutomator2Options()
options.platform_name = "Android"
options.automation_name = "UiAutomator2"
options.avd = "YOUR_AVD_NAME"
options.browser_name = "Chrome"

# Chrome must be installed on the emulator and compatible with ChromeDriver.
driver = webdriver.Remote(
    command_executor="http://127.0.0.1:4723",
    options=options,
)
try:
    driver.get("https://example.com")
    if not driver.save_screenshot("chrome-emulator.png"):
        raise IOError("Screenshot could not be written")
finally:
    driver.quit()

Chrome and ChromeDriver compatibility is a separate prerequisite from the Android emulator itself. A session can fail before the screenshot call if those versions are incompatible.

Make the capture deterministic

Wait for the intended state

Taking a screenshot immediately after a navigation or tap can capture a loading screen. Wait for a known element, application state, or an explicit short delay that reflects a real UI transition. Prefer a condition tied to the UI rather than an arbitrary long sleep.

Choose the output path deliberately

Use an absolute or project-relative path whose parent exists and is writable. Keep one file per test or include a timestamp/build identifier when parallel runs could overwrite one another.

Capture after interaction

Call the method only after dismissing dialogs, scrolling to the required region, or selecting the correct tab. Selenium captures what is currently displayed; it does not reconstruct earlier states.

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.

Check the return value

save_screenshot returns a Boolean. Treat False as a failed write and raise an error rather than allowing a test pipeline to report a missing artifact as success.

Relevant capabilities and scope

The exact option names and validation rules depend on the installed Appium Python Client and UiAutomator2 driver. The commonly required choices are:

Setting Purpose When to use it
platform_name Selects Android Every Android session
automation_name Selects UiAutomator2 Native Android and Android Chrome automation
avd Selects an Android Virtual Device When Appium should launch or target a named emulator
app_package and app_activity Identifies a native app entry point Native app testing
browser_name Selects Chrome in a web context Chrome testing; leave the app capability empty

Use the current driver reference to verify additional capabilities such as device identifiers, launch behavior, and timeout settings before adding them to a production script.

Troubleshooting

“Could not connect” or session-creation errors

Check that Appium is running at the exact URL in command_executor, that the port is reachable, and that the UiAutomator2 driver is installed. Then verify Android SDK and Java environment variables and confirm that the AVD name is spelled exactly as configured.

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

The emulator is not found

Start the AVD manually and verify that Android Debug Bridge lists it, or use the avd option with a valid AVD name. A cold boot can take substantially longer than a warm boot, so do not request the screenshot before the session reports readiness.

Chrome session fails

Ensure Chrome is installed in the emulator and that the Chrome version is compatible with the ChromeDriver used by Appium. Native-app capabilities and browser capabilities describe different session types; do not combine them casually.

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.

The file is missing or save_screenshot returns false

Inspect the destination directory, permissions, filename extension, and available disk space. Create the parent directory first when necessary and use the return-value check shown above.

The image is blank or the content is unavailable

Some Android apps set FLAG_SECURE to prevent screenshots for security reasons. Appium identifies this as a condition that can block capture. Remove or change that protection only in an app build and test environment where you are authorized to do so; do not attempt to bypass another app’s security controls.

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

The image does not include the emulator frame

That is expected. Selenium and Appium capture the controlled Android viewport. Use a host desktop screenshot tool for the emulator application window, borders, or surrounding desktop.

Performance, reliability, and cost considerations

A screenshot is an additional device and file-I/O operation, so capture only the checkpoints you need in large suites. Reuse one session for related steps, but create isolated sessions when test state must be independent. Save artifacts locally during a run and upload them after the test if network storage is slow. In parallel execution, assign each worker a separate emulator or otherwise enforce device/session isolation and unique output names.

The software components in this workflow do not establish a universal runtime, compatibility percentage, or success rate. Results vary with emulator image, host resources, Android version, Appium server, driver, Selenium, and application behavior. Pin versions in continuous integration and record them with each artifact so a later failure can be reproduced.

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

Or skip the browser setup

If you need a website image rather than an Android app viewport, ScreenshotNeo provides a single HTTP request. Its API accepts a URL and returns PNG, JPEG, WebP, or PDF; documentation is at https://screenshotneo.com/docs/.

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.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp

ScreenshotNeo removes cookie and consent banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing result. Its MCP server lets Claude, Cursor, and other MCP clients call take_screenshot, get_page_info, and capture_pdf. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. Create a free ScreenshotNeo account.

FAQ

Can Selenium capture an entire Android emulator window?

Not through the WebDriver screenshot method. It captures the controlled device or browser viewport; desktop-window capture requires a host operating-system tool.

Does save_screenshot return image data?

No. It writes a PNG and returns a Boolean. Use get_screenshot_as_png() for bytes or get_screenshot_as_base64() for Base64 data.

Can I use this with a physical Android phone?

The same Appium and UiAutomator2 approach can target a connected device, but the AVD-specific setup is replaced by device connection and identification settings.

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

Frequently Asked Questions

Which driver should I choose for a native Android app?

Use Appium’s UiAutomator2 driver and create the Python session with Android platform and native app capabilities.

What format does Selenium save by default?

save_screenshot saves the current WebDriver window as a PNG.

Why is my screenshot different from what I see on my monitor?

The API captures the WebDriver-controlled Android viewport, not necessarily the host display, emulator frame, or other desktop windows.

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.

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