Python - Selenium - Take screenshot of webpage

By xngo on June 20, 2019

Selenium is able to take screenshot of the webpage that it visited. This feature is useful when the appearance of the webpage needs to be reviewed by either the graphic designer or by your clients. As a result, you can automatically send screenshots to your reviewers for every new release.

from selenium import webdriver
 
# Create chrome driver.
driver = webdriver.Chrome()
 
# Open the webpage.
driver.get("https://openwritings.net")
 
# Take screenshot of https://openwritings.net.
driver.get_screenshot_as_file("screenshot-of-openwritings.png")
 
# Close.
driver.close()

Output

Screenshot taken by Selenium

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.