Recommended Free Tools
To save the original image file, use Selenium to find the image’s URL, then download its bytes with Python. To save what the browser displays, use Selenium’s screenshot method instead. The two results are different: a screenshot is a PNG of the browser window, not necessarily the image asset itself.
Choose what you need to save
Before writing code, decide whether the output should be the image file the page uses or a picture of the page as rendered in the browser.
- Original image: Find the image URL in the page and request that resource, then write its response bytes to a file. This preserves the image returned by the server rather than capturing the surrounding page.
- Browser screenshot: Use WebDriver’s screenshot method to save the current browser window as a PNG. It captures the view, which may include page layout and other visible elements.
If the image is behind a login or depends on browser cookies, use a request tied to the browser session rather than assuming an ordinary HTTP request will work.
Save an image found on a page
The example below opens a page, waits for an image element to become visible, reads its src attribute, downloads the URL with Requests, and writes the response to an images folder. It assumes that the first visible img is the desired image and that its URL can be accessed without browser authentication.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
#1 Best Overall
- Install the required packages and configure a compatible Chrome WebDriver installation for your environment.
- Replace the example page URL and, if necessary, the CSS selector with the page and image you want.
- Run the script. It creates the output folder and saves one file named
imagewith the URL path’s extension, or.imgif the URL has none.
from pathlib import Path
from urllib.parse import urlparse
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
out_dir = Path("images")
out_dir.mkdir(parents=True, exist_ok=True)
driver = webdriver.Chrome()
try:
driver.get("https://example.com/gallery")
image = WebDriverWait(driver, 15).until(
EC.visibility_of_element_located((By.CSS_SELECTOR, "img"))
)
image_url = image.get_attribute("src")
if not image_url:
raise RuntimeError("The image element has no src URL")
response = requests.get(image_url, timeout=30)
response.raise_for_status()
suffix = Path(urlparse(image_url).path).suffix or ".img"
(out_dir / f"image{suffix}").write_bytes(response.content)
finally:
driver.quit()
Target a specific image
A broad selector such as img may match a logo, thumbnail, avatar, or another image before the one you want. Use a selector specific to the page, for example img.product-photo, if the site’s markup provides a reliable class or other identifier. The example waits for visibility; if the target image is present but not visible, choose a wait condition appropriate to the page and your goal.
Understand which image URL you found
Reading src is a useful starting point, not a universal rule for every site. Responsive images can offer multiple variants; lazy-loaded pages may populate image attributes later; CSS backgrounds are not represented by an img element; and JavaScript may create or replace URLs. Inspect the rendered page and decide which URL corresponds to the variant you intend to keep. There is no single image-selection rule that applies across sites.
Check the downloaded response
raise_for_status() stops the script for an unsuccessful HTTP status instead of silently saving an error page as though it were an image. A URL’s path may not contain a useful file extension, and an image-like URL can return something other than image data. For production use, inspect the response headers and content before choosing an extension or treating the file as an image.
Download an image that requires the browser session
A separate requests.get() call does not automatically inherit the cookies from Selenium’s browser. If the image server expects an authenticated session, that plain request may be rejected even though the image appears in the browser.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →The Selenium 4.49.0 Python API documents driver.request as an HTTP request context that synchronizes browser cookies. Use the request context for a resource that depends on the active session, then check its response before writing the bytes. The exact code should match the Selenium version installed in your environment:
Rank #2
image_url = image.get_attribute("src")
if not image_url:
raise RuntimeError("The image element has no src URL")
response = driver.request.get(image_url)
response.raise_for_status()
suffix = Path(urlparse(image_url).path).suffix or ".img"
(out_dir / f"image{suffix}").write_bytes(response.body)
This snippet assumes the variables and imports from the preceding example and that the installed Selenium version provides the documented request context. Cookie synchronization can help with session-dependent requests, but it does not guarantee access: the site’s own authentication, authorization, or other access controls still apply. Selenium also exposes cookies visible to its active WebDriver session.
Save a screenshot of the browser window
For a PNG of the current browser window, call save_screenshot(). The following complete example checks the method’s return value and closes the driver even if navigation or saving fails.
from selenium import webdriver
driver = webdriver.Chrome()
try:
driver.get("https://example.com/gallery")
saved = driver.save_screenshot("page.png")
if not saved:
raise OSError("Could not save screenshot")
finally:
driver.quit()
Remove the leading space before driver = webdriver.Chrome() in the code above when copying it; the correct line starts at the beginning of the line. Selenium documents save_screenshot(filename) as saving the current window to PNG and returning False on an I/O error. If you need the screenshot as bytes instead of writing it directly to a file, Selenium also provides get_screenshot_as_png().
Wait for dynamic and lazy-loaded images
Selenium navigation normally waits for the page-load event, but that does not mean every image has finished appearing. Pages may fill image URLs through JavaScript, load content after an AJAX request, or defer images until they approach the viewport. An explicit wait for the relevant element or state is more reliable than assuming navigation alone means the image is ready.
- Wait for the particular image, not just any image, when the page contains several.
- If the element exists but its URL is populated later, wait for the relevant attribute or page state before reading it.
- For lazy loading, make sure the page has reached a state in which the desired image is loaded before retrieving the URL.
The appropriate condition depends on the site’s markup and behavior; the sample’s visibility wait is not a universal guarantee that the final desired image variant has loaded.
Use a browser-managed download when appropriate
If the site offers a download button and you want the browser to handle the download, configure the browser’s download location and any relevant download preferences, trigger the page’s action, then wait for the resulting file. Browser preferences and download behavior vary by browser and version.
Selenium’s FAQ includes Firefox download-folder and MIME-type preferences, but that example is legacy documentation and should not be copied as though it were current cross-browser Selenium 4 syntax. Check the current documentation for the browser and Selenium versions you are actually using before configuring download preferences.
Free tools Windows power users keep installed
One-click scans. No signup required.
Or skip the browser setup
If your goal is a screenshot of a webpage rather than downloading its original image asset, ScreenshotNeo can return an image or PDF through a screenshot API. A single GET request is enough:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/gallery -o shot.webp
See the ScreenshotNeo documentation for request options. Cookie banners, popups, and chat widgets are removed before capture; bot checks, blank pages, and failed loads are never billed. An MCP server lets AI agents take screenshots, and 1,000 screenshots a month are free with no card; paid plans start at $5 for 3,000. Sign up for free.
Troubleshoot common problems
The script saves a screenshot, but I need the original image
save_screenshot() captures the current browser window as a PNG; it does not fetch the image resource’s original bytes. Locate the image URL and download its response instead.
The image element is not found or has no URL
The page may still be populating content, the selector may not match the intended element, or the site may use a different mechanism such as a CSS background. Wait for the specific page state, inspect the rendered element, and identify the URL that represents the image you want.
The request fails although the image is visible in the browser
The image may require cookies from the active browser session. Try Selenium’s documented request context when supported by your installed version, and check the response status. Session cookies do not override the site’s access controls.
The saved file is an error page or has the wrong extension
Do not infer success from the URL alone. Check the HTTP status and response content type before treating the bytes as an image; choose a filename extension that reflects the response rather than relying solely on the URL path.
The page loaded, but the image is missing
A page-load event may happen before JavaScript-driven or lazy-loaded content is ready. Add an explicit wait for the target image or the state that supplies its final URL.
The browser prompts for a download or saves somewhere unexpected
Download prompts and destination folders are governed by browser settings. Configure the current browser’s supported preferences and verify its version; do not assume legacy Firefox preferences shown in older Selenium documentation work unchanged across browsers.
Practical reliability and cost considerations
For a single public image URL, a Python HTTP download is simpler than asking the browser to download the file. The browser is still valuable for rendering JavaScript-driven pages and discovering the URL. Use a browser-synchronized request when the active session matters, and verify status and content before writing data. For many URLs or large files, build in site-appropriate pacing, retries, and storage handling; the cited Selenium guidance does not establish a universal speed, quota, or cost figure.
Best Value
Respect the website’s access rules and applicable rights when saving image files. A URL visible in a browser does not itself establish permission to reuse the image.
Frequently Asked Questions
Does Selenium save the original image when I call save_screenshot()?
No. It saves a PNG screenshot of the current browser window. Download the image URL to get the image resource.
Can I save an image that only appears after I log in?
Potentially. Selenium’s current Python API documents a request context with browser-cookie synchronization; the site’s access controls still determine whether the request succeeds.
Do these 3 things before closing this tab:
1Clear out junk files and repair common Windows errors2Fix the driver behind crashes, sound loss and screen glitches3Repair Windows errors before they cause bigger problemsWhy does an image URL lack a file extension?
Some URLs do not include a useful extension. Check the response and use a filename extension appropriate to the returned content.
Quick Recap
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.

