Free tools Windows power users keep installed
One-click scans. No signup required.
Use Selenium 4 or later to find the element’s shadow host, open its shadow root, locate the descendant from that root, then call the descendant WebElement’s screenshot API. In Python, use target.screenshot_as_png for PNG bytes or target.screenshot('/absolute/path/target.png') to save a PNG file.
Find the element inside the shadow DOM
A shadow DOM is an encapsulated DOM tree attached to a host element. A normal driver-level search does not cross that boundary: first find the host, then search within its shadow root.
As an Amazon Associate I earn from qualifying purchases.
- Locate the shadow host from the WebDriver instance, using the page’s actual selector.
- Read the host’s
shadow_rootproperty. - Call
find_elementon that root to locate the desired descendant. - Take the screenshot from the descendant WebElement.
The pattern below uses Selenium’s Python bindings and requires Selenium 4 or greater for the documented shadow-root methods. See Selenium’s element-finding guide.
Runnable Python example
Replace the URL, host selector, and target selector with values from the page you are testing. The example saves the element screenshot as a PNG:
#1 Best Overall
from selenium import webdriver
from selenium.webdriver.common.by import By
url = "https://example.com"
host_selector = "my-component"
target_selector = ".target"
# Assumes a compatible browser and driver are installed and available.
driver = webdriver.Chrome()
try:
driver.get(url)
host = driver.find_element(By.CSS_SELECTOR, host_selector)
root = host.shadow_root
target = root.find_element(By.CSS_SELECTOR, target_selector)
target.screenshot("/absolute/path/target.png")
finally:
driver.quit()
The absolute output path must be valid and writable on the machine running the test. Selenium’s Python API documents screenshot as saving a PNG and recommends a full path. The Python WebElement API documents the screenshot methods and shadow-root property.
Keep the PNG in memory
If a later step consumes image data directly, use the bytes property instead of writing a file:
Rank #2
png_bytes = target.screenshot_as_png
png_bytes contains binary PNG data. You can pass it to code that accepts bytes or save it using your preferred file or image library. The API documents both this property and the file-saving method; it does not establish a quality or performance advantage for either.
Nested shadow roots
If the target is inside a shadow root that is itself inside another shadow root, repeat the host-to-root lookup at each boundary. Each next host is found from the current root, not from the top-level driver.
outer_host = driver.find_element(By.CSS_SELECTOR, "outer-component")
outer_root = outer_host.shadow_root
inner_host = outer_root.find_element(By.CSS_SELECTOR, "inner-component")
inner_root = inner_host.shadow_root
target = inner_root.find_element(By.CSS_SELECTOR, ".target")
target.screenshot("/absolute/path/target.png")
The Python ShadowRoot API describes locating descendants within a shadow root.
Which element should you screenshot?
Use the located descendant WebElement representing the visual area you want. Selenium documents an element screenshot operation; the relevant flow is to find the desired descendant inside the root and call its screenshot method. The documented method is not a screenshot method on the ShadowRoot itself. Selenium maps the WebElement operation to WebDriver’s element screenshot endpoint, as shown in its Python remote connection API.
Browser and version compatibility
The Selenium finder guide says the documented shadow-root methods require Selenium 4 or greater. The Python WebElement reference lists Chromium, Firefox, and Safari for shadow_root. That is not a version-by-version guarantee for every browser, driver, and end-to-end element screenshot combination. Confirm compatibility using the exact Selenium, browser, and driver versions deployed by your project.
Troubleshooting
- NoSuchShadowRoot: The selected element may not be a shadow host, or it may not yet have an attached shadow root. Confirm the host selector and page state before reading
host.shadow_root; Selenium documents this error when no root is attached. - Target lookup fails: Make sure the target selector is searched from the correct root. A descendant inside a shadow tree is not found by searching only from
driver; useroot.find_element(...). For nested components, repeat the lookup at each root. - Host lookup fails: Check that the selector identifies the host in the top-level document and that navigation has reached the expected page before searching.
- Screenshot file is missing: Verify that the process can write to the specified absolute path and that the filename ends in
.png. For an in-memory result, usescreenshot_as_pngand handle the returned bytes in your own code. - Behavior differs by environment: Check the installed Selenium, browser, and driver versions together. The cited API reference identifies browsers for
shadow_root, but does not promise identical results for every version combination.
Or skip the browser setup
For a normal URL screenshot rather than a Selenium-specific shadow descendant, ScreenshotNeo provides a one-request screenshot API. It cannot target an element inside your page’s shadow root by selector through the method shown here; use Selenium when you need that element-level control.
Best Value
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. ScreenshotNeo accepts cookie and consent banners before capture and removes more than 60 known consent platforms, newsletter popups, and chat widgets; each cleanup step can be turned off. Bot checks and CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing, and responses identify the page verdict and billing status. Its MCP server provides take_screenshot, get_page_info, and capture_pdf for AI agents. The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots.
Sign up free for 1,000 screenshots a month, with no card required.
Frequently Asked Questions
Can I capture the screenshot without saving it to disk?
Yes. Read target.screenshot_as_png to get PNG bytes in memory.
Does Selenium’s documented shadow-root support include Safari?
The Python WebElement reference lists Safari, along with Chromium and Firefox, for the shadow_root property. Check your particular Selenium, browser, and driver versions for the end-to-end workflow.
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.




