94

Is there a way to maximize the chrome browser window using python selenium WebDriver?

Note: I am using Chrome Driver 23.0 Any solution on this would be greatly appreciated!

Naveen Subramani
  • 2,134
  • 7
  • 20
  • 27

10 Answers10

127

You could use ChromeOptions and set suitable argument:

options = ChromeOptions()
options.add_argument("--start-maximized")
driver = ChromeDriver(options)
Hugo
  • 27,885
  • 8
  • 82
  • 98
Janek Królikowski
  • 1,101
  • 1
  • 9
  • 10
  • 1
    not working for me - the window snapshot show that the size is only 800x600 – Nam G VU Jun 16 '17 at 06:58
  • 2
    @NamGVU check what's the actual screen resolution while executing test - the maximum size is the size of the resolution. I had this problem some time ago because of test being run by process executed as a service. This caused process to be run in Session 0, which has limited capabilities when it comes to screen resolution. Running tests not in a services solves that issue. – Janek Królikowski Jul 12 '17 at 10:45
  • I run it on ubuntu server; so i guess the screen size set by Xvfb. Thanks to point it out. – Nam G VU Jul 13 '17 at 11:25
  • 18
    This is 2017/12/15 now. `driver.fullscreen_window()` works. – Sraw Dec 15 '17 at 09:41
  • 9
    **driver.maximize_window()** is more comfortable function that works with **selenium chrome driver** in **python**. – Avraham Zhurba Jan 02 '19 at 22:21
  • This is July 2022, the last comment code works, driver.maximize_window() please credit it. – WLiu Jul 08 '22 at 08:50
62

Nothing worked for me except:

driver.set_window_size(1024, 600)
driver.maximize_window()

I found this by inspecting selenium/webdriver/remote/webdriver.py. I've never found any useful documentation, but reading the code has been marginally effective.

Tom Rose
  • 1,539
  • 12
  • 9
  • 2
    This is a better answer than the other ones since this one supports all browsers and not just Chrome. – Dror Mar 04 '19 at 13:27
  • 8
    You don't actually need to set the window size first. – Nouman Oct 03 '19 at 15:45
  • For me, `maximize_window` had no effect. Not doing `set_window_size` kept the window at 800x600, `set_window_size(1920, 1080)` before calling `maximize_window` and when not calling `maximize_window` made the window size 1920x1080. `fullscreen_window` caused my code to hang. I'm using Chrome with `options.add_argument("--headless")`. – Boris Verkhovskiy Apr 17 '20 at 20:41
46

For MAC or Linux:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--kiosk");
driver = new ChromeDriver(chromeOptions);

For Windows:

ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--start-maximized");
driver = new ChromeDriver(chromeOptions);
Graham Russell
  • 997
  • 13
  • 24
Mukesh Rajput
  • 745
  • 6
  • 11
  • 12
    Question is specifically for python. – Zoran Pavlovic May 25 '17 at 07:46
  • 4
    --kiosk is only one that worked for me on Mac. Thanks. – n1c9 Jun 22 '17 at 22:27
  • 1
    Keep in mind that once using `--kiosk`, trying to change window size will crash the driver, example (python): `opts = webdriver.ChromeOptions(); opts.add_argument('--kiosk'); driver = ChromeDriver(chrome_options=opts); driver.set_window_size(800, 600)`. Either fullscreen or windowed. – hoefling Oct 09 '17 at 19:34
45

Based on what Janek answered, this worked for me (Linux):

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")

driver = webdriver.Chrome(chrome_options=options)
smottt
  • 3,272
  • 11
  • 37
  • 44
16

Try this:

driver.manage().window().maximize();
roncsak
  • 618
  • 1
  • 8
  • 21
8

This works for me, with Mac OS Sierra using Python,

options = webdriver.ChromeOptions()
options.add_argument("--kiosk")
driver = webdriver.Chrome(chrome_options=options)
gsun
  • 417
  • 3
  • 7
6

I do the following:

from selenium import webdriver
browser = webdriver.Chrome('C:\chromedriver.exe')
browser.maximize_window()
Limbo
  • 623
  • 8
  • 24
4

Try

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");
arctic_monkey
  • 153
  • 2
  • 4
  • 16
4

try this, tested on windows platform and it works fine :

from selenium import webdriver
browser = webdriver.Chrome('C:\\Users\\yeivic\\Downloads\\chromedriver')
browser.fullscreen_window()
browser.get('http://google.com/')
Victor Marrerp
  • 157
  • 1
  • 4
3

this works for me

driver.maximize_window()
driver.get(url)