簡體   English   中英

如何在無頭ChromeDriver中獲取屏幕截圖?

[英]How can I get a screenshot in headless ChromeDriver?

我試圖在無頭的ChromeDriver實例中捕獲屏幕截圖。 我可以在沒有無頭的情況下獲得正確的截圖。

我試圖僅為此舉例說明,但是,該示例無法正常工作。

    public static void main(String[] args) throws Exception{
            ChromeOptions chromeOptions = new ChromeOptions();
            chromeOptions.setBinary("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
            chromeOptions.addArguments("--headless");

            WebDriver driver = new ChromeDriver(chromeOptions);
            driver.navigate().to("https://adobe.com");

            File srcFile = ((TakesScreenshot)driver).getScreenshotAs(OutputType.FILE);
            // Now you can do whatever you need to do with it, for example copy somewhere
            FileUtils.copyFile(srcFile, new File("testscreenshot.png"));
            driver.quit();

    }

上面代碼生成的屏幕截圖將為空白,側面有一個滾動條。 如何在無頭模式下捕獲屏幕截圖? 這可能嗎?

這種行為在Windows,Ubuntu和Mac上有所不同。 我目前正在使用Mac。 由於某種原因,它沒有呈現頁面。 這是我拍攝截圖之前所需要的全部內容

new WebDriverWait(driver, 10)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM