How To Capture Screenshot Using Selenium WebDriver

Capture Screenshot Using Selenium WebDriver:

Test cases may fail while executing the test cases. While we are executing the test cases manually we just take a screenshot and place in a result repository. The same can be done by using Selenium WebDriver. Here in this post, we see how to capture a screenshot using Selenium WebDriver.

Some of the scenarios we may need to capture screenshot using Selenium WebDriver.

i. Application issues
ii. Assertion Failure
iii. Difficulty to find Webelements on the web page
iv. Timeout to find Webelements on the web page

Must Read: How To Capture Screenshot of Failed Test Cases Using Selenium WebDriver

Syntax to capture and save the screenshot.

Syntax to store it in our local drive

For example:

Below mentioned script shows how to capture a screenshot using Selenium WebDriver.


If you are not regular reader of my blog then I highly recommend you to signup for the free email newsletter using the below link.

Subscribe and get a free eBook and regular updates from

Screenshot Using selenium

Rajkumar SM is a founder of SoftwareTestingMaterial. He is a certified Software Test Engineer by profession and blogger & youtuber by choice. He has an extensive experience in the field of Software Testing. He writes here about Software Testing which includes both Manual and Automation Testing. He loves to be with his wife and cute little kid 'Freedom'.

2 thoughts on “How To Capture Screenshot Using Selenium WebDriver”

  1. Hi RajKumar,

    I have implemented the same code in my program. I have resolved all the issues except the screen shot method File Utils Exception. Can You please guide me on the same. i am planning to integrate Extent reports in my project

    • Hi Azeemuddin Shaik, Check this link

Leave a Comment

Share via
Copy link
Powered by Social Snap