簡體   English   中英

如何使用Selenium WebDriver捕獲網頁的屏幕截圖?

[英]How to capture the screen shot of a webpage using selenium webdriver?

我正在嘗試使用下面提到的腳本來捕獲網頁的屏幕截圖:

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

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

我得到以下方法類型的copyFile未定義。 除了導入java.io.File之外,我是否缺少任何軟件包? 並導入com.sun.jna.platform.FileUtils;。

我使用的方法與您相同,對我來說效果很好。

一個猜測:檢查項目中的導入:

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

導入應為: import org.apache.commons.io.FileUtils;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM