To capture a cross-origin iframe with Selenium, locate the iframe in the parent page and call your Selenium binding’s element screenshot method on it. WebDriver’s documented behavior treats an iframe element screenshot as a capture of that frame’s body region. Cross-origin status does not, by itself, prevent WebDriver from switching into the child browsing context; it does not grant ordinary page JavaScript permission to read the iframe’s DOM.
Choose the capture you actually need
“Screenshot the iframe” can mean several different things. Pick the target before choosing an API, because an element capture, a crop of the parent viewport, and a full capture of the embedded document are not interchangeable.
As an Amazon Associate I earn from qualifying purchases.
| Goal | Approach | Key limitation |
|---|---|---|
| Capture the rendered iframe region | Selenium element screenshot on the iframe element | Confirm that the browser and driver capture the BODY region and crop you expect. The explicit behavior appears in a 2015 W3C WebDriver working draft, not a current final specification. W3C WebDriver working draft |
| Capture exactly how the iframe appears in the parent viewport | Capture the top-level page and crop to the iframe’s visible rectangle | You must account for viewport coordinates, scrolling, scaling, borders and clipping. |
| Capture a precise region with Chromium | Use Chrome DevTools Protocol (CDP) Page.captureScreenshot with its clip parameter |
This is Chromium-oriented and version-sensitive, not a portable WebDriver command. Chrome DevTools Protocol |
| Capture the entire embedded document | Use a full-document strategy appropriate to the browser, or scroll and capture segments | An iframe element screenshot is not automatically a full-page capture of a taller inner document. |
Selenium’s official documentation describes WebDriver as browser automation and documents screenshot methods in its language bindings. The method names and protocol details vary by binding. Selenium documentation
Recommended Free Tools
Capture the iframe element with Selenium in Python
This example waits for the iframe element, then saves its element screenshot as a PNG. Replace the example URL and iframe locator with those used by your page. It assumes Selenium is installed and that a compatible browser and driver are available to your Selenium setup.
#1 Best Overall
- 14" diagonal, 1366x768 resolution, HD BrightView LED, Glossy NON-TOUCH Display
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
url = "https://example.com/page-with-iframe"
iframe_locator = (By.CSS_SELECTOR, "iframe#report")
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(options=options)
try:
driver.get(url)
iframe = WebDriverWait(driver, 20).until(
EC.presence_of_element_located(iframe_locator)
)
WebDriverWait(driver, 20).until(EC.visibility_of(iframe))
if not iframe.screenshot("iframe.png"):
raise RuntimeError("Selenium could not save the iframe screenshot")
finally:
driver.quit()
The WebDriver draft says an element screenshot of a FRAME or IFRAME corresponds to the frame’s BODY. Validate the result in your browser and driver combination: the draft dates to 2015, and it does not guarantee that every implementation will match every requested crop. Selenium’s Python API also documents current-window screenshot methods such as save_screenshot, get_screenshot_as_png and get_screenshot_as_base64; those capture the current window, not necessarily just the iframe. Python WebElement API · Python WebDriver API
Switch into a cross-origin iframe only to inspect or interact
You do not need to switch into the iframe just to take the element screenshot above. Switch when your automation needs to find or operate on elements inside the child document. The cited W3C WebDriver draft explicitly says WebDriver is not bound by the same-origin policy when switching into child browsing contexts. That is a statement about WebDriver automation, not permission for JavaScript running in the parent page to traverse a cross-origin frame’s DOM. W3C WebDriver working draft
iframe = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "iframe#report"))
)
driver.switch_to.frame(iframe)
try:
# Locate or interact with elements inside the frame here.
heading = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.CSS_SELECTOR, "h1"))
)
print(heading.text)
finally:
driver.switch_to.default_content()
Switching changes the context for subsequent element lookups. Return to the top-level document with default_content() before locating parent-page elements. If you only need pixels, the element screenshot is the simpler first attempt.
The Tool Desk
Outbyte PC Repair FREERepair Windows errors before they cause bigger problemsFix Now →Outbyte Driver Updater FREEFix the driver behind crashes, sound loss and screen glitchesFind Drivers →When you need a parent-page crop or a full inner document
Capture the iframe as it appears in the parent viewport
If the element screenshot does not produce the visible rectangle you need, capture the top-level page and crop using the iframe’s geometry. Ensure the rectangle is expressed in the coordinate system expected by your screenshot mechanism. Scrolling, device scale, borders and partial clipping can all shift or reduce the visible region; test those conditions rather than assuming the element’s location alone defines the final crop.
Rank #2
- 256 GB SSD of storage.
- Multitasking is easy with 16GB of RAM
- Equipped with a blazing fast Core i5 2.00 GHz processor.
Use Chromium CDP for a protocol-level clip
Chromium’s CDP Page.captureScreenshot defines a clip parameter, along with image-format and beyond-viewport options. It can be useful for precise region captures, but it is browser-specific and its invocation depends on your Selenium binding and browser version. The protocol documentation does not make it a portable WebDriver method. Chrome DevTools Protocol
Do not confuse the iframe viewport with the embedded page’s full height
The iframe element has a visible rectangle in the parent page. Its inner document can be taller than that rectangle. A screenshot of the iframe region should not be described as a full-page screenshot of the embedded site unless you have verified a separate full-document method. Depending on the requirement, you may need to scroll within the frame and capture segments or use a browser-specific full-page strategy.
Wait for the content you want to photograph
Finding a visible iframe does not prove its embedded content has finished rendering. Lazy loading, navigation, consent screens or delayed content can leave the capture blank or incomplete. A practical sequence is:
Do these 3 things before closing this tab:
1Fix the driver behind crashes, sound loss and screen glitches2Clear out junk files and repair common Windows errors3Scan for outdated or missing drivers - takes under a minute- Wait for the iframe element to be present and visible.
- If content readiness matters, switch into the frame and wait for a known inner element or other condition specific to the page.
- Return to the top-level document if needed, then capture the iframe element.
- Inspect the saved image for clipping, blank areas and the expected content before relying on it in a test or workflow.
There is no universal inner selector or readiness signal: choose one that reflects the content your page requires, and handle consent screens or authentication according to your test setup.
Rank #3
- WINDOWS 11 | STABLE PERFORMANCE: Powered by Intel Celeron N4020 processor and Windows 11 system, this laptop delivers stable performance for everyday computing tasks. It supports web browsing, online learning, document editing, email communication, and basic office work with optimized power efficiency, providing a practical and reliable experience for essential daily use for daily use.
- 15.6” FHD IPS DISPLAY: Features a 15.6-inch Full HD IPS display with narrow bezels, offering wider viewing angles and clearer image details compared to standard panels. The improved screen-to-body ratio enhances visual experience for study, reading, document work, and video playback, making it suitable for both productivity and entertainment use.
- 4GB DDR4 + 128GB eMMC STORAGE: Equipped with 4GB DDR4 memory and 128GB eMMC storage for everyday basics such as browsing, documents, email, and online learning platforms. The built-in TF card slot supports storage expansion up to 1TB, giving you more flexibility for files, photos, videos, and daily documents. TF card not included.
- CONNECTIVITY & PORTS: Includes 1× TF card slot, 2× USB 3.2 Gen1 ports, and 2× full-featured Type-C ports (USB 3.2 Gen1). The Type-C ports support data transfer, charging, and video output, enabling flexible connection with external devices such as monitors, storage, and peripherals for daily work and study use.
- LIGHTWEIGHT DESIGN | ONLINE COMMUNICATION: Designed with a slim, portable profile, this laptop is easy to carry for school, commuting, and travel. A built-in 1MP front camera supports online classes, video meetings, remote communication, and everyday conferencing. The 3300mAh battery works with the low-power system design to support practical daily use, while thermal optimization helps maintain quieter operation during extended tasks.
Troubleshooting
- The locator cannot find the iframe: Check the selector and ensure you are searching from the top-level page, not a different frame context. If the iframe is inserted later, wait for it to appear.
- The screenshot is blank or incomplete: The frame may still be navigating or rendering. Wait for a meaningful inner element, then check for lazy-loaded content, consent walls or other delayed states.
- The element screenshot has the wrong dimensions or crop: Confirm whether you need the iframe BODY region, the parent viewport’s visible rectangle or the entire embedded document. Test the actual browser and driver; the explicit iframe screenshot behavior cited here is from a 2015 working draft.
- Inner elements are not found: Switch to the iframe before looking them up, and return to the parent context with
driver.switch_to.default_content()when finished. - Parent JavaScript gets a cross-origin access error: Do not use page-script DOM access as a substitute for WebDriver context switching. The WebDriver draft’s cross-origin statement applies to automation, not ordinary same-origin policy rules for page JavaScript.
- CDP commands fail or behave differently: Check the Chromium browser version and the binding-specific CDP invocation. CDP is not the portable WebDriver screenshot API.
Portability and protocol direction
Selenium describes WebDriver BiDi as a W3C bidirectional protocol and a cross-browser direction for browser automation, while its documentation also describes functionality currently available through CDP. The reviewed Selenium documentation does not establish BiDi screenshot-capture parity with CDP’s clipped screenshot command, so do not assume an equivalent exists for your setup. Selenium WebDriver BiDi
Or skip the browser setup
For a one-call screenshot API, ScreenshotNeo accepts a URL and returns an image or PDF. Example using cURL:
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com/page-with-iframe -o shot.webp
See the ScreenshotNeo API documentation for request options. ScreenshotNeo removes cookie and consent banners, newsletter popups and chat widgets before the shot; those steps can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and the response identifies the page verdict and billing status in headers. Its MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month with no card; paid plans start at $5 for 3,000 shots. For a page containing an iframe, verify that the returned capture includes the content and region you need.
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 minuteSign up for 1,000 free screenshots a month, with no card.
Frequently Asked Questions
Does an iframe screenshot reveal the iframe’s HTML?
No. It captures rendered pixels; it does not provide the parent page script with access to a cross-origin document’s DOM.
Is Selenium’s iframe element screenshot behavior guaranteed by a current final W3C specification?
The explicit iframe-to-BODY wording cited in this guide is in a 2015 W3C WebDriver working draft, so validate the result with your browser, driver and Selenium binding.
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.
Quick wins for a faster PC:
Repair Windows errors before they cause bigger problemsFix Now →Fix the driver behind crashes, sound loss and screen glitchesFind Drivers →Clear out junk files and repair common Windows errorsFree Scan →




