Selenium take screenshot

Selenium is a web automation framework that can be used for automated testing, web scraping and anything you can do with a web browser. We can use Selenium to take automated screenshots of a webpage.

Related course:
Selenium WebDriver and Python: WebTest Automation Course

Take screenshot Selenium
Selenium will start the given web browser and open the page. It will then take a screenshot and save it to the local hard disk.

take screenshot using python code
take screenshot using python code

We start a web driver (Chromium) and open the webpage
Then we call the method:


The screenshot will be saved in the same directory as the program: the program path.

The full code:

from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/usr/bin/chromium"
driver = webdriver.Chrome(chrome_options=options)

Remember to call driver.close() otherwise the browser stays open after the program finishes.