98

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!

10 Answers 10

137

You could use ChromeOptions and set suitable argument:

options = ChromeOptions()
options.add_argument("--start-maximized")
driver = ChromeDriver(options)
Sign up to request clarification or add additional context in comments.

7 Comments

not working for me - the window snapshot show that the size is only 800x600
@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.
I run it on ubuntu server; so i guess the screen size set by Xvfb. Thanks to point it out.
This is 2017/12/15 now. driver.fullscreen_window() works.
driver.maximize_window() is more comfortable function that works with selenium chrome driver in python.
|
65

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.

3 Comments

This is a better answer than the other ones since this one supports all browsers and not just Chrome.
You don't actually need to set the window size first.
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").
48

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)

2 Comments

This didn't work for me on Linux at first, but updated the Chrome driver with sudo apt install chromium-chromedriver and it worked then.
webdriver.Chrome(options=options)
47

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);

3 Comments

Question is specifically for python.
--kiosk is only one that worked for me on Mac. Thanks.
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.
16

Try this:

driver.manage().window().maximize();

3 Comments

i am using driver.window_maximize().but it doesn't work for chrome browser alone.
AttributeError: 'WebDriver' object has no attribute 'manage'
yeah, this answer is old.
9

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

options = webdriver.ChromeOptions()
options.add_argument("--kiosk")
driver = webdriver.Chrome(chrome_options=options)

Comments

7

I do the following:

from selenium import webdriver
browser = webdriver.Chrome('C:\chromedriver.exe')
browser.maximize_window()

Comments

5

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/')

Comments

4

Try

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-fullscreen");

2 Comments

While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value.
Question is specifically for Python
3

this works for me

driver.maximize_window()
driver.get(url)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.