Saturday, March 10, 2018

How to take screenshot in Selenium WebDriver

Hello welcome to Learn selenium tutorial, In this post we will see how to take screenshot using Selenium WebDriver.

It is most important to take screenshot during our automation testing mostly at the time of faliure condition for verification purpose.
In this we will use TakeScreenshot interface and their method getScreenshotAs.

In selenium webdriver, below line take screenshot:-

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

After taken screenshot we will save this using FileUtils:-

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

In below code, we will open facebook and take screenshot:-



How-to-take-screenshot-in-selenium-webdriver



Hope that you have learnt How to take screenshot in Selenium WebDriver.



1 comment: