Selenium:无法使用aShot库获取完整页面截图 [英] Selenium: Not able to take complete page screenshot using aShot library

查看:738
本文介绍了Selenium:无法使用aShot库获取完整页面截图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试使用 Firefox gecko 驱动程序以及

  driver.get( https://google.com); 

截图fpScreenshot =新的AShot()。shootingStrategy(ShootingStrategies.viewportPasting(1000))。takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),JPEG,新文件(FullPageScreenshot.jpg));

查看了很多变种,但没有任何效果。有趣的是,当我尝试使用旧的firefox版本(46)时,我可以在没有任何第三方库的情况下拍摄完整的屏幕截图。我试图使用最新的Firefox并拥有完整的屏幕截图功能。



任何帮助?

解决方案

使用 ashot-使用 Selenium Java Client v3.12.0 ChromeDriver v2.40 Chrome v 67.0 时1.4.4.jar 这里是一个使用 ChromeDriver aShot Library 水平和垂直拍摄完整页面截图的示例 url https://jquery.com/




  • 代码块:

      import java.io.File; 
    import javax.imageio.ImageIO;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;

    import ru.yandex.qatools.ashot.AShot;
    import ru.yandex.qatools.ashot.Screenshot;
    import ru.yandex.qatools.ashot.shooting.ShootingStrategies;

    公共类ashot_CompletePage {

    public static void main(String [] args)throws Exception {

    System.setProperty(god.bless。你,C:\\Utility\\BrowserDrivers\\chromedriver.exe);
    ChromeOptions选项=新ChromeOptions();
    options.addArguments(start-maximized);
    options.addArguments(disable-infobars);
    options.addArguments( - disable-extensions);
    WebDriver驱动程序=新的C​​hromeDriver(选项);
    driver.get(https://jquery.com/);
    new WebDriverWait(driver,20).until(ExpectedConditions.titleContains(jQuery));
    截图myScreenshot = new AShot()。shootingStrategy(ShootingStrategies.viewportPasting(100))。takeScreenshot(driver);
    ImageIO.write(myScreenshot.getImage(),PNG,new File(./ Screenshots / elementScreenshot.png));
    driver.quit();
    }
    }


  • 屏幕截图:




< img src =https://i.stack.imgur.com/Byv7K.pngalt =screenshot>


Am trying to take the complete page screenshot both horizontally and vertically using Firefox gecko driver and aShot Library.

However, the results are not as expected. Take a look:

driver.get("https://google.com");

Screenshot fpScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(1000)).takeScreenshot(driver);
ImageIO.write(fpScreenshot.getImage(),"JPEG",new File("FullPageScreenshot.jpg"));

Looked into a lot of variants but nothing is working. Interestingly, when I try using old firefox version (46), I am able to take full screenshot without any third party library. Am trying to use latest firefox and have full screenshot functionality.

Any help?

解决方案

While working with Selenium Java Client v3.12.0, ChromeDriver v2.40, Chrome v 67.0 using ashot-1.4.4.jar here is an example to take the complete page screenshot both horizontally and vertically using ChromeDriver and aShot Library of the url https://jquery.com/:

  • Code Block:

    import java.io.File;
    import javax.imageio.ImageIO;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.support.ui.ExpectedConditions;
    import org.openqa.selenium.support.ui.WebDriverWait;
    
    import ru.yandex.qatools.ashot.AShot;
    import ru.yandex.qatools.ashot.Screenshot;
    import ru.yandex.qatools.ashot.shooting.ShootingStrategies;
    
    public class ashot_CompletePage {
    
        public static void main(String[] args) throws Exception {
    
            System.setProperty("god.bless.you", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
            ChromeOptions options = new ChromeOptions();
            options.addArguments("start-maximized");
            options.addArguments("disable-infobars");
            options.addArguments("--disable-extensions"); 
            WebDriver driver =  new ChromeDriver(options);
            driver.get("https://jquery.com/");
            new WebDriverWait(driver, 20).until(ExpectedConditions.titleContains("jQuery"));
            Screenshot myScreenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(100)).takeScreenshot(driver);
            ImageIO.write(myScreenshot.getImage(),"PNG",new File("./Screenshots/elementScreenshot.png"));
            driver.quit();
        }
    }
    

  • Screenshots:

这篇关于Selenium:无法使用aShot库获取完整页面截图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆