我正在测试网页内的游戏,我正在使用的代码是
private void takeScreenShot(String screenShotName) {
File path = new File("/Users/myUser");
String extension = ".jpg";
File screenShot = new File(path+"/"+screenShotName );
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
try {
FileUtils.copyFile(scrFile, screenShot);
} catch (IOException e) {
e.printStackTrace();
}
}
屏幕截图就像这样(我已经在许多应用程序中使用相同的代码而没有任何问题),我在OS X上使用此代码。
答案 0 :(得分:1)
你可以尝试一下:
private void takeScreenShot(String screenShotName) throws AWTException, IOException {
Robot robot = new Robot();
String path = "\\Users\\myUser";
String extension = "jpg";
String fileName = path +"\\"+ screenShotName +"."+ extension;
Rectangle screenRect = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
BufferedImage screenFullImage = robot.createScreenCapture(screenRect);
ImageIO.write(screenFullImage, extension , new File(fileName));
}