October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk5 min

How to Find Broken Images With Selenium WebDriver

A practical Selenium guide to finding failed or unavailable DOM images, waiting for lazy-loaded content, recording useful diagnostics, and understanding what the browser properties do—and do not—prove.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Selenium to inspect each page’s <img> elements after their loads have settled. An image with complete === true and naturalWidth === 0 is a practical signal that the browser has no usable image data. It identifies a failed or unavailable image, not its HTTP status or exact cause.

Check images with Selenium in Python

This runnable pattern navigates to a page, waits for its document load state, then reports settled images whose intrinsic width is zero. Set the target URL and make sure Selenium is installed and a compatible browser and WebDriver are available.

As an Amazon Associate I earn from qualifying purchases.

from selenium import webdriver
from selenium.webdriver.common.by import By

url = "https://example.com"
driver = webdriver.Chrome()

try:
    driver.get(url)
    broken = []

    for image in driver.find_elements(By.TAG_NAME, "img"):
        complete = image.get_property("complete")
        natural_width = image.get_property("naturalWidth")
        natural_height = image.get_property("naturalHeight")

        if complete and natural_width == 0:
            broken.append({
                "src": image.get_attribute("src"),
                "current_src": image.get_property("currentSrc"),
                "natural_width": natural_width,
                "natural_height": natural_height,
            })

    for item in broken:
        print(item)
finally:
    driver.quit()

find_elements returns all matches; if the page has no img elements, the result is an empty list. The script records both the declared src and browser-selected currentSrc, which can differ on responsive images.

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

Run one browser-side scan

For a larger page, use one script execution to collect structured results in the current page context rather than making separate WebDriver property reads for each element:

broken = driver.execute_script("""
return Array.from(document.images, img => ({
  src: img.src,
  currentSrc: img.currentSrc,
  complete: img.complete,
  naturalWidth: img.naturalWidth,
  naturalHeight: img.naturalHeight
})).filter(img => img.complete && img.naturalWidth === 0);
""")

for item in broken:
    print(item)

Use the per-element version when stepping through elements is useful for debugging. The script version can reduce WebDriver round trips and returns the selected fields together. Selenium documents plural element lookup in its element-finder guide and JavaScript execution in its JavaScript WebDriver API.

Interpret the result correctly

Why check both properties

complete means the browser has finished fetching the image; it does not mean the fetch succeeded. It may be true for a broken image. naturalWidth is the image’s intrinsic, density-corrected width; zero indicates that usable intrinsic width is unavailable. Together, after an appropriate wait, these properties provide a useful failure signal. They do not establish a particular HTTP response, network error, or root cause. See MDN’s documentation for image complete and naturalWidth.

Images still loading

Do not label an image as broken merely because its load has not settled. Collect the properties after a suitable wait, or preserve incomplete images as a separate “pending” category and inspect them later. A result set that includes only complete images avoids treating in-flight requests as confirmed failures, but a page can still add or change images after the scan.

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.

Wait for the page you actually need to test

Selenium’s default normal page-load strategy waits for the document’s ready state to become complete. The eager strategy returns at interactive, while resources such as images may still be loading; none does not block navigation on page load. The relevant labels and behavior are described in Selenium’s browser options documentation.

Even complete is not a universal signal that a modern application has finished rendering. JavaScript may insert images after navigation, and lazy-loaded images may not start fetching until they are near the viewport. Selenium’s waiting strategies documentation explains that document ready state covers assets defined in the HTML, while JavaScript can subsequently change the page and create race conditions.

Static pages

For a mostly static page using the default strategy, navigation completion may be sufficient to scan many images. If the page has delayed scripts or late image updates, wait for a page-specific signal or for the image collection and their load states to stabilize.

Lazy-loaded images

Scroll the relevant content into view before classifying its images. Then wait for the page’s own lazy-loading behavior and the image requests to settle. Scanning before scrolling can miss images that have not been requested yet or report them before they are ready.

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

Single-page applications

Wait for an application-specific condition, such as the results container appearing or a known loading indicator disappearing. If no reliable signal exists, poll until the relevant image set stops changing and its images settle, with a bounded timeout. A fixed sleep can be a simple fallback, but it may waste time on fast pages and still be too short on slow ones.

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

Choose the scope of the check

document.images and a page-level img lookup cover DOM image elements in the current browsing context. They do not by themselves validate every asset that appears visually on a page.

  • CSS backgrounds: background images are not img elements; inspect relevant computed styles and validate those URLs separately if they matter.
  • Frames: a scan in the top-level document does not inspect a frame’s document. Switch into each relevant frame and run the check there.
  • Shadow roots: elements inside shadow DOM are not automatically included in a document-level image scan. Traverse the relevant shadow roots if those images are in scope.
  • Responsive images: use currentSrc to record the resource the browser selected; retaining src as well helps explain the markup and diagnose source selection.

Troubleshoot common results

  • No failures appear, but an image looks broken: confirm the element is an img in the inspected context, wait for the actual render, and record currentSrc. The visible asset may instead be a CSS background, live in a frame or shadow root, or have been inserted after the scan.
  • An image appears in the output before it has loaded: do not classify it from a single early observation. Wait for its load to settle and inspect it again; keep it pending if the timeout expires.
  • A valid-looking URL is reported with zero width: the DOM properties establish unavailable intrinsic image data, not why it is unavailable. Use the recorded resource URL and browser/network diagnostics to investigate the cause.
  • The scan misses images loaded while scrolling: scroll through the content first, wait for lazy loading, then scan. Repeat for each relevant region if the page only loads nearby content.
  • Navigation returns before the page is ready for the test: check the configured page-load strategy and add a wait for the page-specific condition. This is especially important with eager, none, and JavaScript-rendered pages.

Or skip the browser setup

If you need a screenshot rather than a Selenium test report, ScreenshotNeo is a website screenshot API and MCP server. It does not replace the DOM-property check above when you need a list of failed image elements, but it can return a screenshot or PDF with one request. The API accepts parameters used by other screenshot APIs, which can make switching easier.

For example, save a WebP screenshot of the target page with cURL:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

See the ScreenshotNeo documentation for API options. Before capture, it can accept cookie or consent banners like a visitor and remove more than 60 known consent platforms, newsletter popups, and chat widgets; each step can be turned off. Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and response headers report the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and other MCP clients. The free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots.

Sign up for ScreenshotNeo’s free plan: 1,000 screenshots a month, no card required.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.