Capture a Selenium screenshot as PNG bytes, wrap those bytes in a binary in-memory stream, and pass the stream to Boto3’s upload_fileobj. This sends the screenshot to an S3-compatible bucket without first creating an image file on disk.
Upload a Selenium screenshot from memory
Selenium’s Python WebDriver method get_screenshot_as_png() returns PNG data as bytes. Boto3’s upload_fileobj accepts a readable binary file-like object, so io.BytesIO can connect the two without an intermediate disk file.
As an Amazon Associate I earn from qualifying purchases.
Install the Python packages in the environment where the script will run:
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallCrashes, No Sound, or Screen Glitches?
Random freezes, missing sound and display glitches usually trace back to one bad driver. Find and replace yours safely.Free scan · under a minutepython -m pip install selenium boto3
The browser driver must also be available to Selenium in your environment. Then configure the endpoint and credentials for your storage provider and run:
#1 Best Overall
- Easily store and access 2TB to content on the go with the Seagate Portable Drive, a USB external hard drive
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
- To get set up, connect the portable hard drive to a computer for automatic recognition no software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
from io import BytesIO
import os
import boto3
from selenium import webdriver
# Set these values for your provider and environment.
endpoint_url = os.environ["S3_ENDPOINT_URL"]
bucket_name = os.environ["S3_BUCKET"]
access_key = os.environ["S3_ACCESS_KEY"]
secret_key = os.environ["S3_SECRET_KEY"]
region_name = os.getenv("S3_REGION", "us-east-1")
s3 = boto3.client(
"s3",
endpoint_url=endpoint_url,
region_name=region_name,
aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
)
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
screenshot = BytesIO(driver.get_screenshot_as_png())
screenshot.seek(0)
s3.upload_fileobj(
screenshot,
bucket_name,
"selenium/example.png",
ExtraArgs={"ContentType": "image/png"},
)
finally:
driver.quit()
After a successful upload, the object key is selenium/example.png in the configured bucket. Change the URL and key to suit your job. The ContentType extra argument marks the object as a PNG for clients that use its object metadata.
Configure the S3-compatible endpoint safely
This example assumes the bucket already exists, the process can read its configured credentials, and the identity has permission to write the requested key. The environment-variable names and the default region shown are example configuration choices, not universal settings for S3-compatible services. Keep access keys out of source control and avoid logging them.
Rank #2
- Easily store and access 5TB of content on the go with the Seagate portable drive, a USB external hard Drive
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
- To get set up, connect the portable hard drive to a computer for automatic recognition software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
Boto3’s session reference describes endpoint_url as a complete custom endpoint URL. Consult your provider’s current instructions for the endpoint scheme and host, region and signing expectations, authentication, TLS certificate requirements, addressing style, and supported operations. Boto3’s S3 examples caution that endpoint overrides can produce unintended behavior, including redirects; test the exact endpoint and bucket configuration you plan to use.
Choose between memory and a local file
| Approach | What the code passes to Boto3 | When it fits |
|---|---|---|
| In memory | A binary stream created from Selenium’s PNG bytes, passed to upload_fileobj. |
When the workflow only needs the bucket object and does not need a local image artifact. |
| Local file | A filename passed to upload_file after Selenium saves the screenshot. |
When another step needs the image on disk or you want to retain a local copy. |
Boto3 documents upload_fileobj as a managed transfer that can use multipart upload in multiple threads when necessary. The in-memory route avoids a separate screenshot file, but the screenshot bytes still occupy process memory while being captured and uploaded.
Rank #3
- Easily store and access 1TB to content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop. Reformatting may be required for Mac
- To get set up, connect the portable hard drive to a computer for automatic recognition no software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
Keep a local PNG as well
Selenium’s save_screenshot saves the current window to a PNG file and returns False on an I/O error. Boto3’s upload_file takes a filename, bucket name, and object key:
from selenium import webdriver
import boto3
import os
bucket_name = os.environ["S3_BUCKET"]
s3 = boto3.client(
"s3",
endpoint_url=os.environ["S3_ENDPOINT_URL"],
region_name=os.getenv("S3_REGION", "us-east-1"),
aws_access_key_id=os.environ["S3_ACCESS_KEY"],
aws_secret_access_key=os.environ["S3_SECRET_KEY"],
)
driver = webdriver.Chrome()
try:
driver.get("https://example.com")
if not driver.save_screenshot("screenshot.png"):
raise OSError("Selenium could not save screenshot.png")
s3.upload_file("screenshot.png", bucket_name, "selenium/example.png")
finally:
driver.quit()
Troubleshoot failed captures and uploads
- Endpoint or redirect errors: Check that
S3_ENDPOINT_URLis the complete URL your provider specifies, including the scheme. Verify region/signing expectations and addressing style, and check whether the provider redirects requests to another endpoint. - Access denied: Confirm that the bucket exists, the credentials belong to the intended identity, and that identity is allowed to write the precise object key.
- Connection or TLS errors: Check network access, the endpoint hostname, and whether your environment trusts the certificate chain required by the provider.
- Invalid stream or empty upload: Pass a binary file-like object. If you read from the stream before upload, reset it with
seek(0); the example does this before callingupload_fileobj. - Browser startup or navigation failure: Verify that Chrome and its driver are available in the runtime and that the target page can load from it. The
finallyblock closes the browser even when capture or upload raises an exception. - Unexpected object metadata: For the in-memory example, retain
ContentType: image/pngif consumers rely on the object being identified as a PNG. The file-based example omits that extra argument.
Or skip the browser setup
ScreenshotNeo can return a screenshot or PDF with one GET request; its API documentation is at screenshotneo.com/docs. For example, save a PNG response with cURL:
Quick Recap
Best Value
- Plug-and-play expandability
- SuperSpeed USB 3.2 Gen 1 (5Gbps)
Rank #4
- Easily store and access 4TB of content on the go with the Seagate Portable Drive, a USB external hard drive.Specific uses: Personal
- Designed to work with Windows or Mac computers, this external hard drive makes backup a snap just drag and drop
- To get set up, connect the portable hard drive to a computer for automatic recognition no software required
- This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable
- The available storage capacity may vary.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before capture. Bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000. See ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.
Quick wins for a faster PC:
Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →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.




