How to capture screenshot of webpage in selenium webdriver


package selenium_examples;


import java.io.File;
import java.io.IOException;

import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.apache.commons.io.FileUtils;

public class Test {

public static void main(String[] args) {


WebDriver driver = new FirefoxDriver();
driver.get("http://funandknowledge.blogspot.com");

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


 try {
FileUtils.copyFile(capturescreenshotFile,new File("E:\\fnkblogscreenshot.png"));
} catch (IOException e) {

e.printStackTrace();
}

 
}
}

Above script takes screenshot of funandknowledge.blogspot.com webpage.Screenshot is stored in E drive with name fnkblogscreenshot.

No comments:

Related Posts Plugin for WordPress, Blogger...