Thursday, September 4, 2025
HomeLanguagesHow to take screenshot using Selenium in Python ?

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 :  

Python3




# 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 image
image.show()


Output : 

 

RELATED ARTICLES

Most Popular

Dominic
32264 POSTS0 COMMENTS
Milvus
81 POSTS0 COMMENTS
Nango Kala
6629 POSTS0 COMMENTS
Nicole Veronica
11799 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11858 POSTS0 COMMENTS
Shaida Kate Naidoo
6749 POSTS0 COMMENTS
Ted Musemwa
7025 POSTS0 COMMENTS
Thapelo Manthata
6698 POSTS0 COMMENTS
Umr Jansen
6716 POSTS0 COMMENTS