Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在所需位置保存屏幕截图_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java 无法在所需位置保存屏幕截图

Java 无法在所需位置保存屏幕截图,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,使用Selenium+Java,我想将测试失败后拍摄的屏幕截图保存在特定位置。为了实现这一点,我编写了以下代码- File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); FileUtils.copyDirectory(srcFile, new File("C:\\verifyTakeScreenshotFailure.png")); 但这会导致错误- java.io.IOException:源代码

使用Selenium+Java,我想将测试失败后拍摄的屏幕截图保存在特定位置。为了实现这一点,我编写了以下代码-

File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);

FileUtils.copyDirectory(srcFile, new File("C:\\verifyTakeScreenshotFailure.png"));
但这会导致错误-

java.io.IOException:源代码 'C:\Users\USER\u NAME\AppData\Local\Temp\screenshot1720506318428476820.png' 存在但不是目录


我正在使用Java8和Selenium3。您能帮我解决这个问题吗?

copyDirectory
用于复制目录。您正在查找
copyFile

FileUtils.copyFile(srcFile, new File("C:\\verifyTakeScreenshotFailure.png"));

如果此答案解决了您的问题,请将其标记为已接受。因此,它也将有助于其他用户。谢谢:)
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
// Now you can do whatever you need to do with it, for example copy somewhere
FileUtils.copyFile(scrFile, new File("C:\\verifyTakeScreenshotFailure.png"));