1

I am using Selenium in Python with Firefox. Firefox is always started in maximized mode, which does not work very well with my tiling window manager Awesome on Linux.

How can I prevent Firefox being opened in maximized mode with Selenium and Python? Or how can I unmaximize a window?

MWE:

#!/usr/bin/python

from selenium import webdriver

driver = webdriver.Firefox()

That opens Firefox in maximized mode on my setup. My regular Firefox doesn't open in maximized mode.

I know the function driver.window_maximize() which apparently doesn't unmaximize the window.

soelderer
  • 35
  • 6
  • 1
    You'll want to set the window size. See [here](https://stackoverflow.com/questions/15397483/how-do-i-set-browser-width-and-height-in-selenium-webdriver) – natn2323 Dec 23 '19 at 19:39
  • 1
    Does this answer your question? [How do I set browser width and height in Selenium WebDriver?](https://stackoverflow.com/questions/15397483/how-do-i-set-browser-width-and-height-in-selenium-webdriver) – natn2323 Dec 23 '19 at 19:39
  • Thanks, setting the window size indeed did the trick. – soelderer Dec 23 '19 at 20:58

1 Answers1

1

Use an instance of firefox.options to add the argument --window-size to open Firefox in any size as follows:

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.add_argument("--window-size=900,600")
driver = webdriver.Firefox(options=options, executable_path=r'C:\WebDrivers\geckodriver.exe')
driver.get('http://google.com/')

Reference

You can find a couple of detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thanks, setting the window size did the trick. I had to use commandline options `-width=900` and `-height=600`, though. Also, I got the warning that `firefox_options=options` is deprecated and should be replaced by `options`. – soelderer Dec 23 '19 at 20:57
  • @soelderer That was my bad, replaced `firefox_options` with `options`. Let me know the status. – undetected Selenium Dec 23 '19 at 20:59
  • Works just fine, thanks. However, the right commandline options (at least for my version of firefox on linux) appear to be `-width=` and `height=`, `--window-size` didn't work for me. – soelderer Dec 23 '19 at 21:02
  • Hmm, I am not sure about the specific version of firefox on linux you are using, but it's possible. Thanks for the update, which version/flavour (linux) are you using? – undetected Selenium Dec 23 '19 at 21:07
  • I'm using Firefox 71.0 on Arch. – soelderer Dec 23 '19 at 21:21