How can I set the browser window size when using `google-chrome --headless`?

后端 未结 3 1640
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-08 06:49

I tried setting the browser size on Chrome --headless by using Selenium WebDriver commands.

I get this WebDriver error:

      - Failed: un         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-08 07:15

    I found it. Simply pass the --window-size command line argument to Google Chrome, for example --window-size=1920,1080.

    In a Protractor configuration this would look like this:

    capabilities: {
        browserName: 'chrome',
        chromeOptions: {
            args: ['headless', 'window-size=1920,1080']
        }
    }
    

    The cool thing is that the windows size is not limited to the current display. It is truly headless, meaning it can be as large as needed for the tests.

    Java code:

    options.addArguments("window-size=1920,1080");
    

    I expand a bit more on this in Headless protractor not sharding tests.

提交回复
热议问题