Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在selenium中使用ashot的可滚动屏幕截图不适用于internet explorer 11版本,但在chrome和firefox中运行良好_Java_Selenium_Internet Explorer 11_Screenshot_Ashot - Fatal编程技术网

Java 在selenium中使用ashot的可滚动屏幕截图不适用于internet explorer 11版本,但在chrome和firefox中运行良好

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

您可以使用以下方法在IE中拍摄完整的页面截图:

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