2

Currently, I'm running Selenium v4 locally on a normal PC with a graphics card and monitor. However, in production, I plan on running Selenium on a server that does not have a monitor.

When I call: driver.maximize() it maximizes the browser the the same height as the monitor/display. What behavior can I expect in production when the server does not have a display/monitor? How big will it maximize the window?


Update

I know you could run Selenium in headless mode but this is not my question. My question is how does Selenium/WebDriver maximize the size of the browser in this case, when it normally uses the size of the monitor/display to do so? What reference point is it using?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

2 Answers2

1

From the Resizing and positioning windows section of the WebDriver specification:

To maximize the window, given an operating system level window with an associated top-level browsing context, run the implementation-specific steps to transition the operating system level window into the maximized window state. If the window manager supports window resizing but does not have a concept of window maximization, the window dimensions must be increased to the maximum available size permitted by the window manager for the current screen. Return when the window has completed the transition, or within an implementation-defined timeout.

In short, executing Selenium based tests on a server that does not have a monitor using driver.maximize(), the command invokes the window manager-specific maximize operation, if any, on the window containing the current top-level browsing context. This typically increases the window to the maximum available size without going full-screen.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks! Upvoted and accepted! Re: _the command invokes the window manager-specific maximize operation, if any, on the window containing the current top-level browsing context_ I guess this means that I would need to delve into the documentation of the OS I'm using to know how WebDriver will execute this function? For example, I plan on using CentoOS so I would need to check the docs to see how the window manager executes the maximize operation? – Agustin Netto Apr 14 '22 at 17:27
  • 1
0

You could try using get_window_size to get the size of the maximized window in headless mode.

  • Thanks. But this is a workaround; it doesn't address the fundamental question: how does selenium determine the size when calling maximize().. – Agustin Netto Apr 12 '22 at 07:13