2014-02-10 56 views

回答

0

將屏幕截圖保存到桌面上的文件夾的代碼。

public static void ScreenShot() throws IOException { 
    WebDriver driver = new FirefoxDriver(); 
    driver.get("http://www.yahoo.com/"); 
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS); 
//Takes screenshot 
    File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE); 
    // Now you can do whatever you need to do with it, for example copy somewhere 
    String path; 
    path = "C:/Users/owner/Desktop/screenshots/" + scrFile.getName();//goes to the path and automatically gives name 
    FileUtils.copyFile(scrFile, new File(path)); //copies the screenshot file to the given path. 

} 
相關問題