Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.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库获取完整的页面截图_Java_Selenium_Selenium Chromedriver_Geckodriver_Ashot - Fatal编程技术网

Java Selenium:无法使用aShot库获取完整的页面截图

Java Selenium:无法使用aShot库获取完整的页面截图,java,selenium,selenium-chromedriver,geckodriver,ashot,Java,Selenium,Selenium Chromedriver,Geckodriver,Ashot,我正在尝试使用FirefoxGeckodriver和 然而,结果并不像预期的那样。看一看: 研究了很多变体,但都不起作用。有趣的是,当我尝试使用旧的firefox版本(46)时,我能够在没有任何第三方库的情况下拍摄完整的屏幕截图。我正在尝试使用最新的firefox并拥有完整的屏幕截图功能 有什么帮助吗?使用ashot-1.4.4.jar使用Selenium Java Client v3.12.0、ChromeDriver v2.40、ChromeV67.0时,这里有一个例子,可以使用url的C

我正在尝试使用
FirefoxGecko
driver和

然而,结果并不像预期的那样。看一看:

研究了很多变体,但都不起作用。有趣的是,当我尝试使用旧的firefox版本(46)时,我能够在没有任何第三方库的情况下拍摄完整的屏幕截图。我正在尝试使用最新的firefox并拥有完整的屏幕截图功能

有什么帮助吗?

使用ashot-1.4.4.jar使用Selenium Java Client v3.12.0、ChromeDriver v2.40、ChromeV67.0时,这里有一个例子,可以使用url的ChromeDriverashot库水平和垂直截图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;
    
    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();
        }
    }
    
  • 截图:


参考 在使用Selenium Java Client v3.12.0、ChromeDriver v2.40、,Chrome v 67.0使用ashot-1.4.4.jar这里是一个示例,使用url
ChromeDriver和ashot库在水平和垂直方向截取完整的页面截图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;
    
    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();
        }
    }
    
  • 截图:


参考 您可以在

中找到详细的讨论,请尝试:

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(ShootingStrategies.scaling(1.75f), 1000)).takeScreenshot(driver);
其中1.75f是设备像素比率(您可以在浏览器控制台中运行
window.devicePixelRatio;
来查找它)。 如果仍无法捕获全屏,请将其更改为2f,然后重试:

Screenshot screenshot = new AShot().shootingStrategy(ShootingStrategies.viewportPasting(ShootingStrategies.scaling(1.75f), 1000)).takeScreenshot(driver);
其中1.75f是设备像素比率(您可以在浏览器控制台中运行
window.devicePixelRatio;
来查找它)。
如果仍然无法捕获全屏,请将其更改为2f

,而不是使用aShot Library,为什么不在浏览器中切换到全屏,然后使用Selenium按Windows+打印屏幕键?以及如何将其转换为jpeg文件?检查这些链接是否对您有帮助:而不是使用aShot Library,为什么不在浏览器中切换到全屏,然后使用Selenium按Windows+打印屏幕键?以及如何将其转换为jpeg文件?检查这些链接是否对您有帮助:并尝试了一些旅游网站,如booking.com/expedia.com,结果是:垂直完成屏幕截图,但水平一半。
ShootingStrategies
在1.4.4版本中提供,但在aShot的1.5.2版本中提供。我只是在尝试。@DebanjanB我怎样才能用水平尺寸来显示完全垂直尺寸?i、 e.1920xFullSize、1280xFullSize等@Eugenetruts默认策略应该有效。你还可以提出一个新问题,提出你的具体要求,这样我就可以为你的问题构造一个答案吗?@DebanjanB尝试了一些旅游网站,如booking.com/expedia.com,结果是:垂直完整的屏幕截图,但水平一半。
ShootingStrategies
在1.4.4版本中不可用,但在1.5.2版本中可用阿肖特。我只是在尝试。@DebanjanB我怎样才能用水平尺寸来显示完全垂直尺寸?i、 e.1920xFullSize、1280xFullSize等@Eugenetruts默认策略应该有效。要不然,你能提出一个新问题,提出你的确切要求,这样我就可以为你的问题构造一个答案吗?@DebanjanB我需要在视口粘贴中添加一个缩放策略,以使其正常工作,否则,它就会被切断。感谢您为已接受的答案添加了补充有用的信息。我需要在视口粘贴中添加缩放策略以使其正常工作,否则,它将被切断。感谢您在接受的答案中添加补充有用的信息。