【问题标题】:How to capture the screen shot of a webpage using selenium webdriver?如何使用 selenium webdriver 捕获网页的屏幕截图?
【发布时间】:2012-10-26 03:17:21
【问题描述】:

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

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;.

【问题讨论】:

    标签: java webdriver


    【解决方案1】:

    我正在使用与您相同的方法,并且对我来说效果很好。

    一个猜测:检查项目中的导入:

    import org.apache.commons.io.FileUtils;
    

    这可能会导致您遇到的错误...

    顺便说一句,这是我的方法,效果很好:

    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);
    }
    

    【讨论】:

      【解决方案2】:

      导入应该是:import org.apache.commons.io.FileUtils;

      【讨论】:

        猜你喜欢
        • 2023-01-23
        • 1970-01-01
        • 1970-01-01
        • 2014-07-15
        • 2020-01-29
        • 2022-01-13
        • 1970-01-01
        • 2019-03-11
        • 2023-03-04
        相关资源
        最近更新 更多