To capture only an iframe’s visible rectangle, locate its <iframe> element in the parent page and call the element’s screenshot method. To capture the whole browser window, use the WebDriver screenshot method instead. Switching into the iframe is necessary for working with elements inside it, but does not crop a window screenshot to the frame.
Choose the screenshot boundary you need
- Iframe only: Find the iframe in the parent document and save a screenshot of that WebElement.
- Whole current window: Use a WebDriver screenshot method. This captures the current window, not just the iframe.
- Elements inside the iframe: Switch WebDriver into the frame before locating or interacting with those inner elements. Switching context does not itself change the screenshot boundary.
Capture only the iframe in Selenium Python
Selenium begins in the top-level document, where the iframe element itself can be located. Use the iframe WebElement’s screenshot method for an image of its displayed rectangle:
from selenium.webdriver.common.by import By
iframe = driver.find_element(By.CSS_SELECTOR, "iframe")
iframe.screenshot("iframe.png")
This saves a PNG file at the supplied path. The example assumes driver is an initialized Selenium WebDriver and the page has already loaded. The selector shown matches the first iframe; use a more specific selector if the page contains several.
Locate a particular iframe
For example, if the iframe has an ID or a distinctive attribute, target that rather than relying on the first matching frame:
Recommended Free Tools
#1 Best Overall
iframe = driver.find_element(By.CSS_SELECTOR, "iframe#report-frame")
iframe.screenshot("report-frame.png")
Replace the selector with one that matches the actual page. The iframe must be present in the parent document when you locate it. Selenium’s frame guide explains that element lookups are made in the current document context; initially that is the top-level document. Selenium: Working with IFrames and frames.
Capture the whole current browser window
If the artifact should include the page around the iframe, use a driver-level screenshot method instead:
Rank #2
driver.save_screenshot("page.png")
Selenium Python also documents driver.get_screenshot_as_file(path), which saves a screenshot to a file, along with methods that return PNG bytes or a base64 representation. These WebDriver methods capture the current window. Switching into an iframe does not turn them into iframe-only captures. See the Selenium Python WebDriver API.
Switch into an iframe to inspect its contents
Switch to the frame when your next operation is to find or manipulate DOM elements inside it. Locate the iframe while still in the parent document, then switch using its WebElement:
Rank #3
from selenium.webdriver.common.by import By
iframe = driver.find_element(By.CSS_SELECTOR, "iframe")
driver.switch_to.frame(iframe)
# Find or interact with elements inside the iframe here.
inner_element = driver.find_element(By.CSS_SELECTOR, "body")
# Return to the top-level document when finished.
driver.switch_to.default_content()
WebDriver can also switch by frame name or ID, or by index. To move up one level from a nested frame, use driver.switch_to.parent_frame(); to return directly to the top-level document, use driver.switch_to.default_content(). The switching options are described in the official frame guide.
Common problems and fixes
- The iframe cannot be found: Confirm the selector matches an iframe in the current document. If the iframe is itself inside another frame, switch into its parent frame before searching for it.
- The screenshot contains the page instead of only the iframe: You likely called a driver-level screenshot method. Locate the iframe WebElement and use its element screenshot method for the frame rectangle.
- Elements inside the iframe cannot be found: Switch into the iframe before searching for inner-document elements. Switch back to the parent or default content when done.
- The element screenshot method is unavailable: Check the Selenium Python version installed in the project and its WebElement API. The exact method support can vary by language binding and version; do not assume the Python call works unchanged in another binding.
Version and behavior checks
The Selenium frame guide reports a modification date of July 29, 2025, and the Python API reference cited here is labeled Selenium 4.50.0. The element screenshot example is for Selenium Python; confirm support against the binding and version actually installed in your project. Browser-specific behavior was not established here, so validate the screenshot in your target browser and environment.
Rank #4
Or skip the browser setup
If you need a screenshot of a URL rather than a Selenium-driven test, ScreenshotNeo provides a website screenshot API. A single GET request can return an image or PDF; this cURL example requests a WebP screenshot:
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 documentation for request options. Cookie banners, popups and chat widgets are removed before the shot; 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.
Quick wins for a faster PC:
Clear out junk files and repair common Windows errorsFree Scan →Scan for outdated or missing drivers - takes under a minuteDriver Scan →Sign up for ScreenshotNeo and get 1,000 free screenshots a month with no card.
Best Value
Frequently Asked Questions
Do I need to switch into an iframe to screenshot it?
No. Locate the iframe from its parent document and use its WebElement screenshot method. Switch into it only to inspect or manipulate its inner DOM.
Can I use Selenium’s driver screenshot method for an iframe-only image?
No. Driver-level screenshot methods capture the current browser window; use the iframe element screenshot method for the iframe rectangle.
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.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.

