首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用selenium中的ashot的可滚动屏幕截图不适用于internet explorer 11版本,但适用于chrome和firefox。

使用selenium中的ashot的可滚动屏幕截图不适用于internet explorer 11版本,但适用于chrome和firefox。
EN

Stack Overflow用户
提问于 2018-07-27 12:42:44
回答 1查看 1.5K关注 0票数 1
代码语言:javascript
复制
    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);

}

sample output

EN

回答 1

Stack Overflow用户

发布于 2018-07-27 17:51:31

你可以使用以下方法在IE中截取整个页面的截图:

代码语言:javascript
复制
/**
     * @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));
     }

希望这对您有帮助:)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51550875

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档