{"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.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install selenium-screenshot"],"cli":null},"imports":["from Screenshot import Screenshot_Clipping"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}