Selenium Webdriver - 截屏时出错

时间:2014-08-15 11:56:08

标签: selenium

 public void testTakeScreenshot()
  {
      try{

          File fscreenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
          System.out.println(fscreenshot.getPath());

          File fdest = new File("E:/");
          FileUtils.copyFile(fscreenshot,fdest);
          System.out.println(fdest.getPath());

      }catch(Exception e)
      {
          e.printStackTrace();
      }
  }

控制台上的生成输出:

C:\用户\ Bunty \应用程序数据\本地\ TEMP \ screenshot1773089913844817102.png java.io.IOException:目标'E:\'存在,但是目录

测试运行正常,但文件创建如控制台中所示。在复制链接时。我找不到同样的文件。复制功能也不起作用;因此,E驱动器中没有文件。

1 个答案:

答案 0 :(得分:3)

正如错误消息所示,您不应该提供目录('E:\')的路径,而应该是文件的路径。尝试:

File fdest = new File("E:/screenshot.png");