{"id":10217,"library":"selenium-screenshot","title":"Selenium Screenshot","description":"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.","status":"active","version":"3.0.0","language":"en","source_language":"en","source_url":"https://github.com/PyWizards/Selenium_Screenshot","tags":["selenium","screenshot","web scraping","web testing","automation","image processing"],"install":[{"cmd":"pip install selenium-screenshot","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Core dependency for browser automation and WebDriver interaction.","package":"selenium","optional":false},{"reason":"Required for image manipulation and saving screenshots.","package":"Pillow","optional":false}],"imports":[{"note":"The main class `Screenshot_Clipping` is exposed directly under the `Screenshot` package namespace, not `selenium_screenshot` or `selenium-screenshot`.","wrong":"from selenium_screenshot import Screenshot_Clipping","symbol":"Screenshot_Clipping","correct":"from Screenshot import Screenshot_Clipping"}],"quickstart":{"code":"import os\nfrom selenium import webdriver\nfrom selenium.webdriver.common.by import By\nfrom selenium.webdriver.chrome.service import Service\nfrom selenium.webdriver.chrome.options import Options\nfrom webdriver_manager.chrome import ChromeDriverManager\nfrom Screenshot import Screenshot_Clipping\n\n# Setup Chrome options for headless mode and window size\nchrome_options = Options()\nchrome_options.add_argument('--headless')\nchrome_options.add_argument('--disable-gpu')\nchrome_options.add_argument('--window-size=1920,1080') # Recommended for consistent headless screenshots\n\n# Initialize WebDriver\n# Using webdriver_manager to automatically handle driver downloads\nservice = Service(ChromeDriverManager().install())\ndriver = webdriver.Chrome(service=service, options=chrome_options)\n\nob = Screenshot_Clipping.Screenshot()\n\ntry:\n    driver.get('https://www.google.com')\n    print(f\"Navigated to {driver.current_url}\")\n\n    # Take a full-page screenshot using CDP (requires Chrome/Chromium-based browser)\n    full_page_screenshot_path = ob.full_Screenshot(driver, save_path=os.getcwd(), image_name='google_full_page.png')\n    print(f\"Full-page screenshot saved to: {full_page_screenshot_path}\")\n\n    # Find an element and take its screenshot\n    search_box = driver.find_element(By.NAME, 'q')\n    element_screenshot_path = ob.get_element_screenshot(driver, search_box, save_path=os.getcwd(), image_name='google_search_box.png')\n    print(f\"Element screenshot saved to: {element_screenshot_path}\")\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    driver.quit()\n    print(\"WebDriver closed.\")","lang":"python","description":"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."},"warnings":[{"fix":"Ensure your WebDriver is Chrome/Chromium-based for optimal performance with `full_Screenshot`. Review documentation for any changes to specific parameters or behaviors.","message":"Version 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.","severity":"breaking","affected_versions":"<3.0.0"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Always add `chrome_options.add_argument('--window-size=WIDTH,HEIGHT')` (e.g., `1920,1080`) to your Chrome options when running in headless mode.","message":"When 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.","severity":"gotcha","affected_versions":"All versions, more critical in <3.0.0"},{"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)`.","message":"For `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-17T00:00:00.000Z","next_check":"2026-07-16T00:00:00.000Z","problems":[{"fix":"Ensure the package is correctly installed: `pip install selenium-screenshot`. Verify your Python environment (e.g., virtual environment) is active.","cause":"The `selenium-screenshot` package was not installed or was installed in an environment not accessible by the script.","error":"ModuleNotFoundError: No module named 'Screenshot'"},{"fix":"Double-check the element locator (e.g., `By.ID`, `By.CSS_SELECTOR`, `By.NAME`). Use explicit waits (`WebDriverWait`) to ensure the element is present and visible before attempting to find it. The element might not exist, be hidden, or not yet loaded when the code executes.","cause":"The WebDriver could not find the element specified by the locator when trying to take an element screenshot.","error":"selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element"},{"fix":"Ensure you pass the WebDriver instance to the method: `ob.full_Screenshot(driver, save_path=..., image_name=...)`.","cause":"The `full_Screenshot` method was called without passing the `driver` (WebDriver) instance as the first argument.","error":"TypeError: Screenshot_Clipping.full_Screenshot() missing 1 required positional argument: 'driver'"},{"fix":"Upgrade to `selenium-screenshot` v3.0.0 or later. Use a Chrome/Chromium-based browser with the latest `chromedriver`. Ensure the browser window size is set adequately, especially in headless mode (`--window-size`). For extremely complex cases, you might need to manually scroll and stitch images, or use a dedicated headless browser service.","cause":"This was a common issue in versions prior to 3.0.0. Even in v3.0.0+, it can happen if not using a Chrome-based browser, or if the page has extremely complex dynamic content or infinite scrolling that the library cannot fully capture.","error":"Screenshots are cropped, cut off, or incomplete, especially for long pages."}]}