How to take screenshot using Selenium in Python ?

Selenium offers a lot of features and one of the important and useful feature is of taking a screenshot. In order to take a screenshot of webpage save_screenshot() method is used. save_screenshot method allows user to save the webpage as a png file.

Syntax :

driver.save_screenshot("image.png")

Argument :
filename or the full path you wish to save your screenshot to.

Action performed :
The screenshot will be saved in the same directory as the program, if path is provided screenshot will be saved at that location only.

Code :

filter_none

edit
close

play_arrow

link
brightness_4
code

# importing webdriver from selenium
from selenium import webdriver
  
from PIL import Image
  
# Here Chrome  will be used
driver = webdriver.Chrome()
  
# URL of website
  
# Opening the website
driver.get(url)
  
driver.save_screenshot("image.png")
  
# Loading the image
image = Image.open("image.png")
  
# Showing the iamge
image.show()

chevron_right


Output :

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.