Best Selenium Libraries for Full Page Screenshots in Python
In this article
The top pick for full-page screenshots in Python is SeleniumBase because it wraps Selenium's native full-page capture into a single method that works reliably across Chrome, Firefox, and Edge, without needing external tools like ImageMagick or manual viewport resizing. It also handles scroll-based stitching automatically for pages with dynamic content, which is the most common pain point with plain Selenium.
What to Look For
When choosing a library for full-page screenshots, focus on these criteria:
- Native vs. stitched capture: Native (via CDP or Firefox's built-in) is faster and handles fixed elements well, but may miss lazy-loaded content. Stitched (scrolling and merging) captures everything but can break on sticky headers or animations.
- Browser support: Chrome, Firefox, Edge, and Safari have different capabilities. Ensure the library supports the browsers you test against.
- Handling of dynamic content: Lazy loading, infinite scroll, or async rendering require waiting or scrolling logic. Libraries that let you inject sleep or wait conditions are more flexible.
- Output format and quality: PNG, JPEG, WebP? Can you set scale factor (device pixel ratio) for crisp images on high-DPI screens?
- Ease of use: A single method call beats writing your own scrolling loop and image stitching code.
- Maintenance and community: Selenium itself updates often; a library that tracks those changes is less likely to break.
SeleniumBase
Strengths: SeleniumBase provides driver.save_screenshot(full_page=True) which uses CDP (Chrome DevTools Protocol) for Chrome/Edge and a scroll-stitch fallback for Firefox. It handles lazy loading by auto-scrolling and waiting. It also supports mobile emulation and device scale factor settings.
Trade-offs: It's a full test framework with many features (pytest integration, proxies, UC mode), which may be overkill if you only need screenshots. The API is more opinionated than raw Selenium, and the learning curve is steeper if you're not already using it.
Who it suits best: Teams already using SeleniumBase for testing, or those who need reliable full-page captures across multiple browsers without writing custom stitching code.
Plain Selenium + CDP (Chrome/Edge)
Strengths: Using Selenium's built-in CDP support, you can call Page.captureScreenshot with captureBeyondViewport: true. This gives you a native full-page screenshot in one shot, with no stitching artifacts. It's fast and preserves the exact layout.
Trade-offs: Only works on Chromium-based browsers (Chrome, Edge, Brave). For Firefox, you'd need a different approach. You must write a few lines of code to set the device metrics and capture the screenshot, and handle the base64 encoding yourself.
Who it suits best: Developers who are comfortable with Selenium's lower-level APIs and only target Chrome/Edge. It's ideal for CI pipelines where speed matters.
Selenium + Firefox Built-in (FullPageScreenshot)
Strengths: Firefox has a native Page.captureScreenshot equivalent via its own protocol (Marionette) that supports full-page capture. Selenium exposes this through the save_screenshot method with the full_page option in some versions, or you can use the Firefox-specific fullPageScreenshot command.
Trade-offs: This feature is less documented and has been inconsistent across Firefox versions. It may not capture lazy-loaded content unless you scroll manually first. Also, it doesn't work on Chrome.
Who it suits best: Teams that must support Firefox and want a native solution without extra dependencies, and are willing to test against Firefox updates.
Pillow + Custom Stitching (DIY)
Strengths: Using Pillow (PIL) to stitch together viewport screenshots gives you complete control. You can implement your own scrolling logic, handle lazy loading, and merge images with transparency or scaling. It works on any browser.
Trade-offs: This is the most labor-intensive approach. You must handle viewport height detection, scroll offsets, and image merging, and you'll likely run into issues with fixed headers, iframes, or parallax effects. It's error-prone and slow.
Who it suits best: Projects with very specific needs (e.g., capturing only a certain section, or adding watermarks) that can't be met by existing libraries, and where you have time to maintain the code.
PyAutoGUI (for non-Selenium full-page)
Strengths: PyAutoGUI takes OS-level screenshots, so it can capture the entire screen, not just the browser viewport. It works with any browser or application, and you can combine it with Selenium to scroll and capture.
Trade-offs: It's not a Selenium library, and it captures the whole screen, so you'll need to crop the browser window manually. It's also platform-dependent and can be flaky if the window moves or if the screen resolution changes. Not recommended for headless CI.
Who it suits best: Local debugging or quick manual captures where you need the entire desktop, not just a web page.
Playwright (as a Selenium alternative)
Strengths: Playwright has first-class support for full-page screenshots via page.screenshot(full_page=True), and it handles lazy loading out of the box. It's faster than Selenium and offers auto-waiting, which reduces flakiness.
Trade-offs: It's not Selenium, so you'd need to rewrite your test code. If you're already invested in Selenium, this is a migration, not a drop-in fix.
Who it suits best: New projects that haven't committed to Selenium yet, or teams that are open to switching to a more modern tool for better screenshot reliability.
How to Choose
Budget: All the options here are open-source and free. The cost is in time: SeleniumBase saves you time but has a learning curve; DIY costs more time upfront but gives flexibility. If you're in a hurry, go with SeleniumBase or CDP.
Use case: For CI/CD with Chrome, CDP is the fastest and most reliable. For cross-browser testing, SeleniumBase is the best bet. For a one-off script, plain Selenium with a simple scroll-and-stitch using Pillow might be overkill, but it's doable.
Common trade-offs: Native capture misses lazy-loaded content; stitching can produce artifacts. If you need both speed and completeness, consider a hybrid: use CDP for the initial capture, then scroll to trigger lazy loading and stitch if needed. Also, be aware of fixed elements — they'll appear multiple times in stitched images unless you hide them with JavaScript.
Frequently Asked Questions
Does Selenium's save_screenshot capture the full page by default?
No, it only captures the visible viewport. You need to use a library like SeleniumBase or CDP commands to get the full page.
Why does my stitched screenshot have duplicate headers?
Fixed or sticky elements are captured in every viewport. You can hide them with JavaScript before scrolling, or use a library that handles this automatically.
Can I take full-page screenshots in headless mode?
Yes, both Chrome and Firefox support full-page capture in headless mode, though you may need to set a large window size or use CDP.
What about lazy-loaded images?
Native capture won't trigger lazy loading. You need to scroll to the bottom first, or use a library that does that for you, like SeleniumBase.
Is there a way to capture full-page screenshots without any extra libraries?
Yes, using CDP directly with Chrome/Edge, or using Firefox's Marionette protocol. But it's more code than SeleniumBase.
Which library is best for mobile viewport screenshots?
SeleniumBase supports mobile emulation and can capture full-page screenshots on mobile viewports. Plain CDP also works with device metrics.
Bottom Line
For most Python users, SeleniumBase is the best choice because it gives you a reliable, cross-browser full-page screenshot with minimal code. If you only target Chrome and want maximum speed, use plain Selenium with CDP. Avoid DIY stitching unless you have very specific requirements that no library can meet.