How to capture Screen Shot in Selenium WebDriver?
Last Updated :
24 Apr, 2025
Selenium is an open-source framework used mainly in web automation tasks. Its sole purpose is in testing web applications but it's not the only thing we can do with selenium. Selenium can also be used in other web-related tasks (such as web scraping, web element interaction, etc). Since Selenium is open source, it has a strong community of developers that helps other users by providing documentation, GitHub support, and many more such things making new users comfortable with it. Selenium has support for multiple programming languages including Python, Java, JavaScript, c#, etc. In this article, we going to show one of its use cases i.e. taking screenshots with Selenium and WebDriver. So, hang tight, and let's deep dive into the article.
Capturing Screen Shot using get_screenshot_as_file()
In the first step, we have to install the Selenium package in Python. We can simply use pip (it's a common package manager in Python). We have to type this command in our command prompt.
pip install selenium
After typing this command in our command prompt, we can see downloading message starts displaying on the command prompt. Wait until the installation is completed.

Create a Python file. Open the Python file (you can use PyCharm, Python idle, Vs code, etc to open it). After we are done with opening the file, import WebDriver from the Selenium library.
from selenium import webdriver
Call webdriver.Chrome( ). This function will open our Chrome. We can specify the location of our webdriver's path in the function but it's optional. This function will automatically open Chrome if it's in the same directory. If it's in the other directory, you must mention the path of our webdriver.
dr = webdriver.Chrome()
Now, we have to specify the URL of the website/web page we wish to capture the screenshot. Now call get_screenshot_as_file(), it stores the file in the path provided as an argument.
dr.get_screenshot_as_file("C:\screengfg\scr.png")
Python3
from selenium import webdriver
#accesing the chrome browser
dr = webdriver.Chrome()
#providing the page url
pageUrl = "http://www.geeksforgeeks.org/"
dr.get(pageUrl)
#invoking the function to take screen shot and store it in mentioned location
dr.get_screenshot_as_file("C:\screengfg\scr.png")
#closing the browser
dr.quit()