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

Use Selenium’s save_screenshot() to write the current browser window to a local PNG, then upload that file with Boto3’s upload_file(). Configure the S3 client for the bucket’s actual region—not simply the region where the test runner happens to run. AWS lists Mumbai as ap-south-1 and Hyderabad as ap-south-2.

Capture a screenshot and upload it with Boto3

This example assumes you already have a working Selenium WebDriver session in driver, an existing S3 bucket, and credentials that permit writing to the selected object key. It creates the local directory, checks Selenium’s result, then uploads the PNG with its content type set.

from pathlib import Path
import boto3

# `driver` is an existing Selenium WebDriver session.
# Use a unique run_id to avoid overwriting screenshots from other runs.
run_id = "replace-with-test-run-id"
bucket = "your-existing-bucket"
region = "ap-south-1"  # Mumbai; use ap-south-2 if the bucket is in Hyderabad.
object_key = f"selenium-screenshots/{run_id}/checkout.png"
local_path = Path("artifacts") / run_id / "checkout.png"
local_path.parent.mkdir(parents=True, exist_ok=True)

if not driver.save_screenshot(str(local_path)):
    raise OSError(f"Selenium could not save screenshot to {local_path}")

s3 = boto3.client("s3", region_name=region)
s3.upload_file(
    str(local_path),
    bucket,
    object_key,
    ExtraArgs={"ContentType": "image/png"},
)

Install the dependencies in the same Python environment that runs the test with pip install selenium boto3. The Selenium driver setup and browser installation are separate prerequisites; this code begins after the browser session is available.

What the code does

  • save_screenshot() writes a PNG of the current browser window to the supplied path. Selenium recommends using a full path and a .png extension, and its method returns False on an I/O error.
  • The directory is created before capture, so a missing parent directory does not cause the local save to fail.
  • upload_file() accepts a local file name, bucket name, and object name. The object name is the S3 key, including any prefix-like path segments.
  • The unique run identifier organizes artifacts and reduces the chance that concurrent or repeated tests replace an object at the same key. S3 treats the same key as the same object location.

Choose the Indian region that matches the bucket

The location of the Selenium runner does not determine the S3 bucket’s region. Set region_name to the region where the bucket was created. AWS lists these Indian S3 regions and regional REST endpoints:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
#1 Best Overall
Sale
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
  • 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.
Region Region code Regional S3 endpoint
Mumbai ap-south-1 s3.ap-south-1.amazonaws.com
Hyderabad ap-south-2 s3.ap-south-2.amazonaws.com

Confirm the bucket’s region in its AWS configuration, then use that region in the client. If the bucket is in Hyderabad, change the example’s region to ap-south-2. The upload is an authenticated S3 object operation; it does not require a public bucket or an S3 static website endpoint.

Region choice can also depend on organizational data-location requirements and the network path between the runner and bucket. The region names and endpoints alone do not establish which will be faster for a particular workload; measure in the actual deployment if latency matters.

Rank #2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
  • 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.

Use AWS credentials without putting keys in source code

Boto3 supports multiple credential providers, including credentials configured for the environment and IAM roles. Prefer the runtime’s role or another configured provider over embedding long-lived access keys in test code. AWS recommends IAM roles for code running on EC2; Boto3 can retrieve credentials from an attached instance role through instance metadata.

The identity used by the test runner must be allowed to write the requested object under the bucket’s policy and encryption configuration. The exact least-privilege permissions depend on those settings and the object-key prefix, so verify the policy for your deployment rather than copying a universal policy.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Rank #3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
  • 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.

Handle upload errors and protect the artifacts

Distinguish local capture failures from S3 failures

  • Local save returns false or raises an I/O error: confirm the parent directory exists, the path is writable, and the filename ends in .png. Do not attempt the upload until the screenshot was saved successfully.
  • Upload raises an AWS exception: check the credential provider, bucket name, bucket region, network access, bucket policy, and permission for the chosen key. Include the run ID, bucket, and key in diagnostic logs, but never log credentials or screenshot contents.
  • Repeated tests replace an earlier artifact: ensure the key includes a unique run or build identifier. A stable key intentionally points to one object location, so uploading again to that same key replaces the object there.

upload_file() reports upload failures by raising an error. In production, catch and report AWS exceptions with enough context to identify the failing run while keeping secrets and captured page data out of logs.

Keep access and retention deliberate

S3 buckets and objects are private unless access is granted. Keep screenshots private unless sharing is a real requirement, and use S3 Block Public Access controls. New uploads are encrypted at rest by default with SSE-S3, but encryption does not replace access controls or a retention policy. Decide how long test screenshots should remain available and remove artifacts when they are no longer needed.

Rank #4
Sale
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
  • 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.

Alternative: upload a binary file object

If your code already has the screenshot in a readable binary file-like object rather than a local path, Boto3 provides upload_fileobj(). The file object must be opened in binary mode, not text mode. For Selenium’s normal save_screenshot() workflow, saving locally and using upload_file() is the direct approach.

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 your goal is a website screenshot rather than a Selenium-controlled browser session, ScreenshotNeo can return a screenshot or PDF with one GET request. It is a separate capture workflow, not an upload of your Selenium browser session to your S3 bucket.

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.
Best Value
Sale
UnionSine 500GB Ultra Slim Portable External Hard Drive HDD-USB 3.0
  • [Upgraded Version] - This external hard drive features a mirrored logo stripe combined with a striped anti-slip design, and the rounded corners of the casing make it easier to grip. The stripes also have a heat dissipation function, ensuring stable and fast data transfer.
  • 【Ultra-thin and quiet】 - The motherboard adopts JMicron 578 noise-free solution, giving you a quiet working environment. Lightweight and portable size designed to fit in your pocket for easy portability.
  • 【Ultra-Fast Data Transfers】 - Pairing this external hard drive with JMicron 578 solution USB 3.0 and USB 2.0 interfaces enables blazing-fast data transfer. It boasts theoretical read speeds of up to 125MB/s and write speeds of up to 103MB/s.
  • 【Plug and Play】 - With no software to install, just plug it in and the drive is ready to use.The hard disk chip is wrapped with an aluminum anti-interference layer to increase heat dissipation and protect data.
  • 【What You Get】 - 1 x Portable Hard Drive, 1 x USB 3.0 Cable, 1 x User Manual, Gift-type shell packaging ,Three-year manufacturer's warranty and free technical support services.
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 API documentation for request options. Cookie banners are accepted or removed before capture, along with supported popups and chat widgets; bot checks, blank pages and failed loads are never billed. An MCP server lets AI agents use screenshot tools, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000. Sign up for free.

Frequently Asked Questions

Does Selenium’s save_screenshot method capture the entire page?

No. It saves the current browser window. Use a separate full-page capture approach if the required artifact must include content beyond the visible window.

Can I upload the screenshot directly to a public S3 website URL?

This workflow uploads an object through the authenticated S3 API. Public access and static website hosting are separate configurations and are not required for the upload.

Quick Recap

SaleBestseller No. 1
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
Seagate 2TB Portable Hard Drive | USB 3.0 (STGX2000400)
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.99
Bestseller No. 2
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
Seagate Portable 5TB External Hard Drive HDD – USB 3.0 for PC, Mac, PS4, & Xbox - 1-Year Rescue Service (STGX5000400), Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$229.99
Bestseller No. 3
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
Seagate Portable 1TB External Hard Drive HDD – USB 3.0 for PC, Mac, PlayStation, & Xbox, 1-Year Rescue Service (STGX1000400) , Black
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$119.80
SaleBestseller No. 4
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
Seagate Portable 4TB External Hard Drive HDD – USB 3.0, 1-Year Rescue
This USB drive provides plug and play simplicity with the included 18 inch USB 3.0 cable; The available storage capacity may vary.
$157.73

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.