Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set window-size to fullscreen for headless-chrome using chrome options?

When executing UI tests, I get an error that selenium doesn't support automatic window resizing for chromedriver, which results in tests failing.

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 do not want to hard-code values for width and height, is there some way I can do this to set fullscreen ?

like image 394
hemanik Avatar asked Jun 28 '17 07:06

hemanik


People also ask

How do I change the window size in headless Chrome?

Therefore, you need to set the desired screen size with an additional argument: ChromeOptions options = new ChromeOptions();options. addArguments("--headless", "--window-size=1920,1200");WebDriver driver = new ChromeDriver(options);

How do I change the window size in Chrome?

This is done with the help of ChromeOptions class. We have to create an object of that and apply addArguments method on it. Then pass window-size=x, y as a parameter to the method. The x and y are the dimensions of the window.

Which of the following option opens Chrome browser in maximized state?

Use the ChromeOptions class This method informs the Chrome browser explicitly to launch in maximized mode.

How do I change the resolution of Chrome using Selenium?

setSize(dem); We can also set the browser width and height with the help of Chrome options. We have to create an object of the ChromeOptions class and apply addArguments to it. The parameter window-size set with values of height and width of the browser are passed as arguments to the method.


1 Answers

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

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

So the maximized window size is not applicable for chrome-headless and needs to be explicitly set by users, if required.

like image 161
hemanik Avatar answered Oct 13 '22 07:10

hemanik