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

Selenium’s standard screenshot methods create PNG images. They do not accept a JPEG or WebP format parameter. To produce a JPG, capture the PNG bytes first, then decode and re-encode them with an image library such as Pillow. Changing screenshot.png to screenshot.jpg only changes the filename; it does not change the image encoding.

What image format does Selenium use?

The Python WebDriver methods get_screenshot_as_file(), save_screenshot(), and get_screenshot_as_png() are PNG-oriented. The Selenium API describes the file methods as saving “a screenshot of the current window to a PNG image file.” The byte method returns PNG bytes in memory. Selenium’s standard API has no format argument for JPEG or WebP.

  • driver.save_screenshot("screen.png") writes a PNG file.
  • driver.get_screenshot_as_file("screen.png") also expects a PNG filename.
  • driver.get_screenshot_as_png() returns PNG bytes that you can pass to another library.

The same limitation applies to an element screenshot, such as element.screenshot("element.png"): capture is PNG-based, so conversion is a separate step.

Why a .jpg extension does not create a JPEG

Image files contain encoded bytes as well as a name. Selenium obtains PNG bytes and writes those bytes directly. If you call driver.save_screenshot("screen.jpg"), the contents are still PNG, even though the suffix says .jpg. Some viewers may detect the PNG signature and open it, while other software will reject it or infer the wrong MIME type. Use a real image encoder to create a JPEG.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Kodak PIXPRO FZ45 16MP Compact Digital Camera, 4X Optical Zoom, AA, Black
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 4x optical zoom with a 27mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • LCD Screen and Battery: 2.7in LCD screen with 2 AA alkaline batteries for convenient on-the-go use

Convert a Selenium PNG to JPEG in Python

Install Selenium and Pillow in the environment that runs your test:

python -m pip install selenium pillow

The following complete example captures https://example.com, converts the in-memory PNG to JPEG, and writes screenshot.jpg:

from io import BytesIO
from PIL import Image
from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--headless=new")

driver = webdriver.Chrome(options=options)
try:
    driver.get("https://example.com")

    png_bytes = driver.get_screenshot_as_png()
    with Image.open(BytesIO(png_bytes)) as image:
        # JPEG has no alpha channel. Flatten transparency onto white.
        if image.mode in ("RGBA", "LA", "P"):
            background = Image.new("RGB", image.size, "white")
            if image.mode != "RGBA":
                image = image.convert("RGBA")
            background.paste(image, mask=image.getchannel("A"))
            image = background
        elif image.mode != "RGB":
            image = image.convert("RGB")

        image.save("screenshot.jpg", "JPEG", quality=90, optimize=True)
finally:
    driver.quit()

quality=90 is a practical starting point for a screenshot containing photographs and text. Lower values generally make a smaller file with more visible artifacts; higher values preserve more detail at the cost of size. Choose a value that matches your downstream limit rather than assuming one quality setting is ideal for every page.

Use a temporary PNG when you prefer file-based processing

from PIL import Image
from selenium import webdriver

with webdriver.Chrome() as driver:
    driver.get("https://example.com")
    driver.save_screenshot("temporary.png")
    with Image.open("temporary.png") as image:
        image.convert("RGB").save("screenshot.jpg", "JPEG", quality=90)

The in-memory version avoids an intermediate file and is useful when uploading the result to another service. The file-based version is convenient when you need the original PNG for debugging or archival.

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

Handle transparency correctly

PNG can carry an alpha channel; JPEG cannot. A transparent screenshot must therefore be composited onto a solid color before JPEG encoding. The first example uses white. If your page is designed for a dark background, replace "white" with a color such as "#111111" (Pillow accepts RGB tuples or color names after conversion as appropriate).

Palette images (P) and grayscale-with-alpha images (LA) are converted to RGBA before compositing. Ordinary RGB screenshots can be saved directly. Converting every image to RGB before saving prevents Pillow from raising a mode-related JPEG error.

Rank #2
Sale
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Black
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • Rechargeable Battery: Included LB-012 lithium-ion battery charges in the camera over USB with the supplied adapter in about 2 hours; charge it for at least 4 hours before first use to maximize battery life

PNG or JPEG: which should you keep?

Requirement PNG JPEG
Transparency Supported, including alpha Not supported; flatten first
Compression Lossless Lossy; controlled with quality
Best fit Sharp text, diagrams, UI pixels, regression comparisons Photographic content or systems that require JPEG
Encoding in Selenium Native output Capture PNG, then re-encode

Keep the original PNG when pixel accuracy, transparency, or visual regression testing matters. Convert to JPEG when a consumer explicitly requires the JPEG MIME type or when lossy compression is acceptable for a photographic page. Confirm what the receiving API accepts; a file ending in .jpg is not enough if the bytes remain PNG.

Element and full-page screenshots

Element screenshots

Locate the element, capture its PNG, and apply the same Pillow conversion:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
element = driver.find_element("css selector", "main")
png_bytes = element.screenshot_as_png
with Image.open(BytesIO(png_bytes)) as image:
    image.convert("RGB").save("main.jpg", "JPEG", quality=90)

If the element includes transparency, use the compositing routine from the full-window example instead of a direct convert("RGB").

Full-page considerations

A normal WebDriver screenshot captures the current viewport. Page-length capture behavior varies by browser and driver; if you need a full page, configure the browser or use a full-page-capable capture workflow first, then convert the resulting PNG. Conversion does not expand the captured area or load images that were never rendered.

Keep PNG bytes for uploads or base64

If the next system accepts PNG, do not convert unnecessarily:

png_bytes = driver.get_screenshot_as_png()
# upload png_bytes with content type image/png

Selenium also exposes PNG-oriented base64 and byte methods. Keeping the native representation avoids an extra decode/encode cycle and preserves lossless pixels.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Sale
Digital Camera, Latest FHD 1080P Digital Camera for Teens with SD Card Anti Shake Point and Shoot Cameras Portable 16X Zoom Compact Small Cameras for Kids Boys Girls Seniors with Wrist Strap
  • Latest Digital Camera Built-in Fill Light : This compact digital camera is paired with a powerful CMOS processor and image stabilization to help you take & record the most exciting moments in 44 MP quality images & FHD 1080P quality videos anywhere, anytime. Plus, there is also a built-in fill light to help you take high quality pictures even in low light&dark settings, making this the perfect camera for all indoors/outdoors situations.
  • Long-Lasting Battery Life & 16X Digital Zoom :This point and shoot camera will retain its battery charge even after long use. The controls and functions are easy to operate making this the perfect choice for children, teens and younger. This kids camera supports 16x digital zoom, you can zoom in or out the subject by pressing the W/T button for taking still photos to zoom in or out on distant objects and capture all the details you need.
  • Multifunctional & Portable Digital Camera: This cheap digital camera is slim enough to fit in your pocket. You'll easily be able to take it with you on all your indoor/outdoor activities and adventures and ideal for beginners, children and teenagers. This kids digital camera is equipped with 20 filters, anti-shaking, self-timer, continuous shooting, date stamp, time-lapse recording, smile capture, internal MIC and speaker (recording sound videos), great for your daily photography needs.
  • WEBCAM & PAUSE FUNCTION : More than just a FHD 1080p digital camera, it also works as a webcam for video calls and vlogging. Connect the camera to the computer, press shutter and power button at the same time and the camera will automatically turn on webcam mode for all your video calling and live streaming needs. The pause function allows you to pause when seeing playback videos.
  • A Must Have Photography Device : This digital camera with SD card made from high-quality materials, this retro camera is safe and durable. Perfect for all ages to develop & improve their photographic abilities and observation skills. Our dedicated and experienced 24/7 support team is available for all after purchase troubleshooting, questions and technical help.

Troubleshooting Selenium image-format problems

The output named .jpg is rejected as an invalid JPEG

Cause: the file contains PNG bytes. Capture to PNG and encode with Pillow, as shown above. Do not rely on renaming.

Pillow reports that JPEG cannot save an RGBA image

Cause: JPEG has no alpha channel. Composite RGBA, LA, or palette data onto a background and convert the result to RGB before calling save.

The converted image has a black or unexpected background

Cause: transparent pixels were flattened against an unsuitable color. Choose the intended background explicitly and composite with the alpha channel rather than dropping it implicitly.

The file is much larger than expected

Reduce JPEG quality gradually, resize before encoding if your delivery requirements allow it, or keep PNG when the image is mostly text and flat UI colors. There is no universal quality value; validate readability at the target dimensions.

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

Text looks soft or shows halos

JPEG is lossy and can damage high-contrast edges. Increase quality, avoid repeated JPEG re-encoding, or retain PNG for pixel-sensitive screenshots.

The browser does not start or the screenshot call fails

Verify that the browser and matching WebDriver are installed, that the process can run in the selected headless mode, and that driver.quit() is reached in a finally block. A browser startup or navigation failure occurs before format conversion and must be fixed in the WebDriver setup.

Rank #4
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Red
  • 16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting
  • Optical Zoom: 5x optical zoom with a 28mm wide angle lens for flexible framing indoors or outdoors
  • Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
  • Memory Support: Works with Class 10 SD, SDHC, or SDXC cards up to 512GB
  • Rechargeable Battery: Included LB-012 lithium-ion battery charges in the camera over USB with the supplied adapter in about 2 hours; charge it for at least 4 hours before first use to maximize battery life

The page is incomplete when captured

Wait for the page state your test requires before calling the screenshot method. Selenium captures what has rendered at that moment; JPEG conversion cannot recover content that was still loading, hidden, or blocked.

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 only need a URL rendered as an image, ScreenshotNeo provides a screenshot API and MCP server. It returns PNG, JPEG, WebP, or PDF directly, so there is no Selenium-and-Pillow conversion step. Before capture it accepts the cookie or consent banner like a visitor and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be disabled. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers identify the page verdict and billing status.

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

One-call cURL example (see the ScreenshotNeo API documentation):

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

The same request in Python:

import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)

And in Node.js:

const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo also offers an MCP server with take_screenshot, get_page_info, and capture_pdf tools for Claude, Cursor, and other MCP clients. Its Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000. Sign up for the free plan.

Operational and cost notes

  • PNG capture plus local conversion uses CPU and memory for decoding and encoding; process large screenshots deliberately and close image objects.
  • JPEG quality changes output size and visual fidelity, so test against the receiving system’s maximum upload size and MIME-type checks.
  • For repeatable tests, keep browser viewport, device scale factor, fonts, and page readiness conditions consistent; format conversion alone does not make captures visually deterministic.
  • Preserve the PNG when you may need to investigate a failed visual test. It is the lossless source from which a JPEG can be regenerated.

Frequently Asked Questions

Can Selenium save screenshots as WebP directly?

The documented Python screenshot methods are PNG-oriented and do not expose a JPEG or WebP format switch. Capture PNG and use an image encoder that supports WebP if that is your required output.

Does changing screenshot.png to screenshot.jpg convert the image?

No. It changes only the filename. The bytes remain PNG until an encoder such as Pillow writes JPEG data.

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.

Can I preserve transparent pixels in a JPEG?

No. JPEG has no alpha channel. Composite the PNG onto a chosen background, or keep PNG when transparency is required.

The Bottom Line

Selenium captures screenshots as PNG. To obtain a genuine JPEG, capture the PNG bytes and re-encode them with Pillow, flattening transparency first; a filename extension alone never changes the format.

Quick Recap

SaleBestseller No. 1
Kodak PIXPRO FZ45 16MP Compact Digital Camera, 4X Optical Zoom, AA, Black
Kodak PIXPRO FZ45 16MP Compact Digital Camera, 4X Optical Zoom, AA, Black
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$99.99
SaleBestseller No. 2
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Black
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Black
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99
Bestseller No. 4
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Red
Kodak PIXPRO FZ55 16MP Compact Digital Camera, 5X Optical Zoom, Red
16MP Sensor: Captures detailed photos with a CMOS sensor for everyday shooting; Full HD Video: Records 1080p video for travel clips, family moments, or simple vlogging
$139.99

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.