How do I set the window size to fullscreen for headless chrome using chrome options?

When running UI tests, I get the error that selenium does not support auto-resizing for the chrome edge, causing the tests to fail.

Is there a way to set this using chrome options for headless-chrome

?

I have tried the following,

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");

      

Also, replacing "--start-maximized"

with "--start-fullscreen"

and "--kiosk"

.

But none of the above worked for me, the only option that works for me is "--window-size=width,height"

.

I don't need hardcoded values ​​for width and height, is there a way to do this to set it to full screen mode?

+7


source to share


3 answers


The problem is that headless mode is meant to be used on computers without screens, so there is no way to figure out what size your screen is, even if you have one. The only way is to pass this information to the browser at -window-size.

The default window size and display size in headless mode is 800x600 on all platforms.



Thus, the maximum window size is not applicable for chrome-mute and must be explicitly set by users if necessary.

+6


source


it worked for me driver.manage().window().setSize(new Dimension(1600,700));



0


source


There is another option. Instead, --start-maximized

you can do:

WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();

      

0


source







All Articles