Latest Posts

How to take screenshot in Selenium WebDriver.

 

package demopackage;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.*;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class ScreenshotExample {
 public static void main(String[] args) throws IOException {
  System.setProperty("webdriver.chrome.driver", "C:\\Work\\chromedriver.exe");
  WebDriver driver = new ChromeDriver();
  driver.manage().window().maximize();
  driver.get("https://www.facebook.com");
  File src = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
  FileUtils.copyFile(src,new File("C:\\Work\\screenshot.png"));
 }

}


No comments:

Post a comment