public void testScreenshot() throws IOException {
    final String desfilepath = "/Users/zhoutu/Desktop/zyj/aaa.png";
    // make screenshot and get is as base64
    final WebDriver augmentedDriver = new Augmenter().augment(driver);
    ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.BASE64);
    // make screenshot and save it to the local filesystem
    final File srcfile = ((TakesScreenshot) augmentedDriver)
        .getScreenshotAs(OutputType.FILE);
    try {
      FileUtils.copyFile(srcfile, FileUtils.getFile(desfilepath), true);
    } catch (final Exception e) {
      System.out.println(e.toString() + "\n");
    }
  }

直接调用即可,建议图片名称采用时间戳,然后传入进来.这样在你的 html 中即可查看你的图片了.


↙↙↙阅读原文可查看相关链接,并与作者交流