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
from selenium import webdriver
from PIL import Image
driver = webdriver.Chrome()
driver.get(url)
driver.save_screenshot( "image.png" )
image = Image. open ( "image.png" )
image.show()
|
Output :
Last Updated :
30 Jun, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...