Saturday, 20 December 2014

Screenshot - entire page

Let's see how one can take screenshot of the entire page .


import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;

public class ScrDemo1 {

public static void main(String[] args) throws IOException {

System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");

WebDriver driver = new InternetExplorerDriver();

driver.navigate()
.to("http://www.toolsqa.com/automation-practice-form/");

            //TakesScreenshot is an interface and we are casting our driver instance to it

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

            //The path where the screenshot should be saved

FileUtils.copyFile(srcFile, new File(
"D:\\Screenshot\\ScrDemo1.png"));

System.out.println("Screenshot captured");

driver.quit();

}

}

This is the screenshot taken :

ScrDemo1 screenshot


Pay It Forward

DR

No comments:

Post a Comment