How to take Screenshots Using Selenium WebDriver

Posted By : Sandeep Rathor | 02-Dec-2016

Selenium Webdriver

If We are using Selenium WebDriver to Automate our Software Web Application then sometime there is need to Capture the Screenshots using Selenium scripts because sometime we have to execute very large number of test cases and in these some test cases are fail so thats's why we need to check that why this test cases has failed.

But before writing the Selenium script you have to add some special liberaries to take screenshot these are:-



import org.openqa.selenium.OutputType;

import org.openqa.selenium.TakesScreenshot;

import org.testng.annotations.Test;

This will help you in Execute the test cases and debug the code in more better way to next time. Here are some basic commands use to write the selenium scripts for capturing the screenshots

File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

You can change the file path and name where you want to share 

FileUtils.copyFile(scrFile, new File("D:\\screenshot.png"));



Request for Proposal

Name is required

Comment is required

Sending message..