public void getScreenShot(){
try {
System.setProperty("webdriver.firefox.bin", "E:/火狐浏览器/Mozilla Firefox/firefox.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://www.baidu.com/");
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddHHmmss"); //转换时间格式
String time = dateFormat.format(Calendar.getInstance().getTime()); //获取当前时间
Thread.sleep(2000);
File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //执行屏幕截取
FileUtils.copyFile(srcFile, new File("F:\\资料图片", time + ".jpg"));
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//利用FileUtils工具类的copyFile()方法保存getScreenshotAs()返回的文件;"屏幕截图"即时保存截图的文件夹
}
selenium中java代码截图
猜你喜欢
转载自blog.csdn.net/weixin_42027884/article/details/86622372
今日推荐
周排行