-1

获取设备屏幕截图时出现故障异常

我的代码如下:

//open the page
driver.get("http://wikipedia.com");
//take another screenshot
try {
        File screenshot = new File("screenshot1.png");
            File tmpScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);           
        }
        catch(IOException e){
            System.out.println("Failed to take screenshot."+e.getMessage());
        }

        //quit
        driver.quit();
    }

任何机构都可以帮我解决这个问题吗?

4

1 回答 1

0

我试图执行你的代码但没有得到异常,虽然我也没有得到截图。我已经修改了你的代码看看这是否适合你

driver.get("http://wikipedia.com");

File screenshot = new File("screenshot1.png");
File tmpScreenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
org.apache.commons.io.FileUtils.copyFile(tmpScreenshot, screenshot);
System.out.println("the screenshot printed at:- " + screenshot.getAbsolutePath());
于 2012-12-26T08:02:33.417 回答