The Wayback Machine - https://web.archive.org/web/20240622171733/https://www.geeksforgeeks.org/how-to-take-screenshot-using-selenium-in-python/
Open In App

How to take screenshot using Selenium in Python ?

Last Updated : 30 Jun, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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 : 

 


Similar Reads

Take and convert Screenshot to PDF using Python
In order to take and convert a screenshot to PDF, firstly the PyAutoGUI can be used which is an automation library in python which can control mouse, keyboard and can handle many GUI control tasks. Secondly, for the conversion PIL(Python Imaging Library) of python can be used which provides image processing facility and it supports many file format
3 min read
How to Take Screenshot of a Div Using JavaScript?
A screenshot of any element in JavaScript can be taken using the html2canvas library. This library can be downloaded from its official website. The below steps show the method to take a screenshot of a <div> element using JavaScript. ApproachIn this approach, we will create a blank HTML document.Include the html2canvas library code by either
2 min read
screenshot() element method - Selenium Python
Selenium’s Python Module is built to perform automated testing with Python. Selenium Python bindings provides a simple API to write functional/acceptance tests using Selenium WebDriver. To open a webpage using Selenium Python, checkout - Navigating links using get method – Selenium Python. Just being able to go to places isn’t terribly useful. What
2 min read
How to take backup of MySQL database using Python?
In this article, we are going to learn how to back up a MySQL database using python. Database used: Python modules required: In this post, we are going to use the mysql-connector module of python to back up our data. You can install mysql-connector with the following command: pip install mysql-connectorBacking Up Database: So, it's a fairly simple
3 min read
How to Take Multiple Inputs Using Loop in Python
Taking multiple inputs in Python is a common task, especially when dealing with user interactions or processing data sets. Using a for loop can simplify the process and make the code more efficient. In this article, we will explore simple and commonly used methods to take multiple inputs in Python using loops in Python. Take Multiple Inputs Using L
3 min read
Measure The Time You Take To Type A Word Using Python
Here, we have task to measure the time takes to type a word in Python. In this article we will see how to measure the time you to type a word in Python, we will type the word and measure the type using some simple generally used methods. Example : Input : Type the word 'GeeksforGeeks': GeeksforGeeks Output: Time taken: 3.04 seconds Typing speed: 25
3 min read
How to take screenshots using python?
Python is a widely used general-purpose language. It allows performing a variety of tasks. One of them can be taking a screenshot. It provides a module named pyautogui which can be used to take the screenshot. pyautogui takes pictures as a PIL(python image library) which supports opening, manipulating, and saving many different image file formats.
1 min read
Python | Pandas TimedeltaIndex.take()
Python is a great language for doing data analysis, primarily because of the fantastic ecosystem of data-centric python packages. Pandas is one of those packages and makes importing and analyzing data much easier. Pandas TimedeltaIndex.take() function return a new Index of the values selected by the indices. We generally pass a list of indices to b
2 min read
Python | Pandas Series.take()
Pandas series is a One-dimensional ndarray with axis labels. The labels need not be unique but must be a hashable type. The object supports both integer- and label-based indexing and provides a host of methods for performing operations involving the index. Pandas Series.take() function return the elements in the given positional indices along an ax
3 min read
Take Matrix input from user in Python
Matrix is nothing but a rectangular arrangement of data or numbers. In other words, it is a rectangular array of data or numbers. The horizontal entries in a matrix are called as 'rows' while the vertical entries are called as 'columns'. If a matrix has r number of rows and c number of columns then the order of matrix is given by r x c. Each entrie
3 min read
Article Tags :
Practice Tags :