Java 在selenium中使用ashot的可滚动屏幕截图不适用于internet explorer 11版本,但在chrome和firefox中运行良好
您可以使用以下方法在IE中拍摄完整的页面截图:Java 在selenium中使用ashot的可滚动屏幕截图不适用于internet explorer 11版本,但在chrome和firefox中运行良好,java,selenium,internet-explorer-11,screenshot,ashot,Java,Selenium,Internet Explorer 11,Screenshot,Ashot,您可以使用以下方法在IE中拍摄完整的页面截图: public static void takeScrollableScreenshot(WebDriver webdriver, String filePath, WebDriverWait wait) throws Exception { File myDirectory = new File(filePath); if(!myDirectory.exists()) { myDirectory.m
public static void takeScrollableScreenshot(WebDriver webdriver, String filePath, WebDriverWait wait) throws Exception
{
File myDirectory = new File(filePath);
if(!myDirectory.exists()) {
myDirectory.mkdirs();
}else{
// Directory already exist
}
Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(500))
.takeScreenshot(webdriver);
ImageIO.write(screenshot.getImage(), "PNG", myDirectory);
}
希望这对您有所帮助:)您遇到了什么错误。我使用的是IE11,它可以正常工作。它可以滚动到页面底部并截图,但我需要整个页面的截图。截图后会截图检查图像。如果删除JavascriptExecutor代码,它也可以工作并截图整个页面(仅在IE中),对于其他浏览器,我们使用ASHOTHE。您是否检查过。
/**
* @param driver
* @param file e.g "C:\\Users\\username\\Desktop\\RegressionTests\\oracle.png"
* @throws IOException
*/
public static void takeScreenshot(WebDriver driver, String file) throws IOException {
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
File scrFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(scrFile, new File(file));
}