2012-11-06 37 views
0

我试图捕捉使用下面提到的脚本的网页的截屏:如何捕获使用硒webdriver的网页的截屏?

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

回答

0

我正在使用和你一样的方法,它对我来说工作正常。

一个猜测:检查进口项目:

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

进口应该是:import org.apache.commons.io.FileUtils;

+0

感谢您纠正我......它工作 – user1776382

相关问题