How to take a screenshot with Selenium?

You can take a screenshot using the selenium web driver via the save_screenshot method.

Here is some sample code for navigating to the ScrapingBee website and taking a screenshot of the page:

from selenium import webdriver

DRIVER_PATH = '/path/to/chromedriver'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)

driver.get("http://www.scrapingbee.com")

screenshot_path = "/path/to/screenshot.png"

# Save the screenshot
driver.save_screenshot(screenshot_path)

Related Selenium web scraping questions: