0

我正在尝试使用下面提到的脚本捕获网页的屏幕截图:

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

FileUtils.copyFile(scrFile, new File("D:\\screenshot.jpg"));

我得到以下 copyFile 方法类型未定义。除了 import java.io.File 之外,我还缺少任何包吗?并导入 com.sun.jna.platform.FileUtils;。

4

2 回答 2

0

I am using the same approach as you and it works fine for me.

One guess: Check imports in the project:

import org.apache.commons.io.FileUtils;

That could be causing the error you are getting...

BTW here is my method which works fine:

public void takeScreenshot(String nameOfOutputFileIncludingExtension) throws IOException {
    File scrFile = new File("");
    scrFile = ((TakesScreenshot)getDriver().getScreenshotAs(OutputType.FILE);
    File destination = new File("target/surefire-reports/" + nameOfOutputFileIncludingExtension);
    System.out.println("Screenshot stored at:" + destination.getAbsolutePath());
    FileUtils.copyFile(scrFile, destination);
}
于 2012-11-06T08:09:07.403 回答
0

Import should be : import org.apache.commons.io.FileUtils;

于 2012-11-06T08:09:36.923 回答