Registry / testing / selenium-screenshot

selenium-screenshot

JSON →
library3.0.0pypypi✓ verified 82d ago

Selenium-screenshot is a Python library that extends Selenium WebDriver capabilities to capture full-page and element-specific screenshots. It's particularly useful for web scraping, testing, and archiving web content. Version 3.0.0 introduced significant improvements, including robust full-page screenshot functionality via Chrome DevTools Protocol (CDP). The library has an active release cadence, with major and minor updates addressing bugs and adding features.

pip install selenium-screenshot
INSTALL
IMPORT
SIG · SELENIUM-SCREENSHO
S
selenium-screenshot
testingpythonv3.0.0
Install
4.3s avg
Import
Disk
73MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.0.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
installs and imports cleanly · install 0.0s · import 0.000s · 72.8MB
glibc
py 3.103.910 runs
installs and imports cleanly · install 4.3s · import 0.000s · 74MB
73MB installed
● package 73MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Screenshot
from Screenshot import Screenshot
from Screenshot import Screenshot_Clipping

This quickstart demonstrates how to set up a headless Chrome WebDriver using `webdriver_manager`, navigate to a page, and then use `selenium-screenshot` to capture both a full-page screenshot and a specific element's screenshot. Version 3.0.0's `full_Screenshot` method leverages Chrome DevTools Protocol (CDP) for more accurate full-page captures.

import os from selenium import webdriver from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chrome.options import Options from webdriver_manager.chrome import ChromeDriverManager from Screenshot import Screenshot_Clipping # Setup Chrome options for headless mode and window size chrome_options = Options() chrome_options.add_argument('--headless') chrome_options.add_argument('--disable-gpu') chrome_options.add_argument('--window-size=1920,1080') # Recommended for consistent headless screenshots # Initialize WebDriver # Using webdriver_manager to automatically handle driver downloads service = Service(ChromeDriverManager().install()) driver = webdriver.Chrome(service=service, options=chrome_options) ob = Screenshot_Clipping.Screenshot() try: driver.get('https://www.google.com') print(f"Navigated to {driver.current_url}") # Take a full-page screenshot using CDP (requires Chrome/Chromium-based browser) full_page_screenshot_path = ob.full_Screenshot(driver, save_path=os.getcwd(), image_name='google_full_page.png') print(f"Full-page screenshot saved to: {full_page_screenshot_path}") # Find an element and take its screenshot search_box = driver.find_element(By.NAME, 'q') element_screenshot_path = ob.get_element_screenshot(driver, search_box, save_path=os.getcwd(), image_name='google_search_box.png') print(f"Element screenshot saved to: {element_screenshot_path}") except Exception as e: print(f"An error occurred: {e}") finally: driver.quit() print("WebDriver closed.")
Debug
Known issues
breakingVersion 3.0.0 introduces significant changes to how full-page screenshots are captured, now primarily utilizing the Chrome DevTools Protocol (CDP). This may require adjustments to existing code, particularly if you were relying on older, less robust full-page methods. The API for `full_Screenshot` remains similar but its underlying implementation is different.
fix
Ensure your WebDriver is Chrome/Chromium-based for optimal performance with `full_Screenshot`. Review documentation for any changes to specific parameters or behaviors.
affects: <3.0.0
gotcha`full_Screenshot` in v3.0.0+ is optimized for Chrome/Chromium-based browsers due to its reliance on the Chrome DevTools Protocol (CDP). While it might fall back to older methods for other browsers, full-page screenshot accuracy and reliability will be best with Chrome.
fix
For consistent and accurate full-page screenshots, use `Chrome` or `Chromium` as your WebDriver. If cross-browser full-page screenshots are critical, thoroughly test the behavior on non-Chrome browsers.
affects: >=3.0.0
gotchaWhen running Selenium in headless mode, especially with older versions or if screenshots appear inconsistent, setting a specific window size (`--window-size`) is crucial for predictable screenshot dimensions and content rendering, even though v3.0.0 improves headless handling.
fix
Always add `chrome_options.add_argument('--window-size=WIDTH,HEIGHT')` (e.g., `1920,1080`) to your Chrome options when running in headless mode.
affects: All versions, more critical in <3.0.0
gotchaFor `get_element_screenshot`, ensuring the target element is visible and correctly located on the page is critical. Issues with elements being off-screen, hidden, or dynamically loaded can lead to `NoSuchElementException` or incomplete screenshots.
fix
Implement explicit waits (`WebDriverWait`) to ensure the element is present and visible before attempting to screenshot it. Scroll the element into view if necessary using JavaScript `driver.execute_script('arguments[0].scrollIntoView();', element)`.
affects: All versions
Upgrade
Version history
3.0.0latest on PyPI · released May 4, 2025
Audit
Dependencies
seleniumrequiredCore dependency for browser automation and WebDriver interaction.
PillowrequiredRequired for image manipulation and saving screenshots.
Agent activity
27 hits · last 30 days
node
24
OpenAI (training)
1
Resources
selenium-screenshot — pip install selenium-screenshot · libregistry