我正在尝试使用 Java 中的 Selenium 获取整页(没有任何滚动条)屏幕截图。我下面的代码在 Firefox 29 中运行完美。我在 Chrome 35 中测试了相同的代码,它正在截取部分屏幕截图(不是整页,带有滚动条的屏幕),并且 IE8 不支持使用 Selenium Drive 进行屏幕截图。
File scrFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File("C://screenshot//" + image1.jpg));
最佳答案
我在任何浏览器中都没有看到屏幕截图有任何问题。对我来说,它需要完整的页面 View 。
您可以尝试使用以下使用augmenter()的方法,该方法通常用于RemoteWebDriver执行。
WebDriver augmentedDriver = new Augmenter().augment(driver);
File f = null;
if (augmentedDriver instanceof TakesScreenshot) {
f = ((TakesScreenshot) augmentedDriver).getScreenshotAs(OutputType.FILE);
} else {
// screenshot not taken
}
关于java - 使用 Selenium JAVA 的 IE 和 Chrome 的整页截图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24269290/