public class Example1 {
public static void main(String[] args) throws IOException, Exception {
System.setProperty("webdriver.chrome.driver","D:\\chromedriver.exe");
//实例化一个Chrome浏览器的实例
WebDriver driver = new ChromeDriver();
//FirefoxDriver driver = new FirefoxDriver();
driver.get("http:www.baidu.com");
//截屏操作
//截图到output
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
try {
String savePath = "D:\\example.jpg";
//复制内容到指定文件中
FileUtils.copyFile(scrFile, new File(savePath));
} catch (IOException e) {
e.printStackTrace();
}
driver.close();
}
}
下面是视频课程上封装的截图方法