Screenshot Using Selenium With Python

Introduction

In this blog, we will understand how to take screenshots using Selenium with Python.

In order to take screenshots, we need to make use of the save_screenshot method provided by the WebDriver instance.

The method takes the filename as an argument, and it will save the screenshot in the current working directory unless you provide an absolute path.

The file name should end with a .png extension

code with an explanation.

# importing the modules
from selenium import webdriver
import time

# using chrome driver
driver=webdriver.Chrome()

# web page url
driver.get("https://demo.automationtesting.in/Register.html")

#call the save screenshot method to take the screenshot
driver.save_screenshot('testingscreenshot.png')

The screenshot image is stored in the absolute path.

Screenshot image

Thanks

Happy learning.....!