Search code examples
pythonseleniumfirefoxawesome-wm

Start firefox unmaximized with selenium in python


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.


Solution

  • 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: