在selenium中使用ashot的可滚动屏幕截图不适用于InternetExplorer11版本,但在chrome和f


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

样本输出

您可以使用以下方法在IE中进行全页面截图:

/**
* @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));
}

希望对你有所帮助:(

相关内容

  • 没有找到相关文章

最新更新