我正在尝试使用以下代码截取屏幕截图:
public void screenShot() throws IOException, InterruptedException { //Take screenshot and save to file
File scr=((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); //Destination where to store screenshot
File dest= new File("filepath/Visionscreenshot_"+timestamp()+".png"); // Copy the file to system ScreenshotPath
FileUtils.copyFile(scr, dest);
Thread.sleep(1200);
}
public String timestamp() {
return new SimpleDateFormat("YYYY-MM-DD HH-mm-ss").format(new Date());
}
我收到此错误:
线程中的异常" main" java.lang.NullPointerException at Vision.Screenshot.screenShot1(Screenshot.java:37)
答案 0 :(得分:0)
好像你需要改变这个:
File dest= new File("filepath/Visionscreenshot_"+timestamp()+".png");
到
File dest= new File("<Some existing folder path from directory>" + "/Visionscreenshot_"+timestamp()+".png");
注意:请注意文件分隔符。
答案 1 :(得分:0)
试试这个:
File dest= new File("filepath\\Visionscreenshot_"+timestamp()+".png");
并确保您的文件路径正确。