4

How I can maximize chrome browser window size to make it fit with using screen size? I have tried doing that using the function driver.maximize_window(). It only maximize height but not width.

The version I'm using is: selenium-server-standalone-3.11.0.jar and python 3.6.4

Here's the code I'm using:

from selenium import webdriver
# get initial window size
driver = webdriver.Chrome()
print(driver.get_window_size())
# set window size
driver.set_window_size(480, 320)
print(driver.get_window_size())
# maximize window
driver.maximize_window()
print(driver.get_window_size())
driver.set_window_size(2560, 1440)
print(driver.get_window_size())
driver.quit()

Output:

{'width': 1200, 'height': 1369}
{'width': 480, 'height': 320}
{'width': 1536, 'height': 1417}
{'width': 2560, 'height': 1417}
jacobcan118
  • 7,797
  • 12
  • 50
  • 95
  • Possible duplicate of [Chrome - org.openqa.selenium.WebDriverException: unknown error: cannot get automation extension at driver.manage().window().maximize();](https://stackoverflow.com/questions/42979877/chrome-org-openqa-selenium-webdriverexception-unknown-error-cannot-get-autom) – undetected Selenium Mar 22 '18 at 19:26
  • in my case, i have multiple monitor, that I set chrome browser should open on 2560x1417. so when I use maximize_window(), it only change height to max not width. – jacobcan118 Mar 22 '18 at 19:35
  • it turns out i try another function driver.fullscreen_window\(). it seems work – jacobcan118 Mar 23 '18 at 00:26

3 Answers3

7

Here is what might help you with your problem if you want to start with an already maximized window:

options = webdriver.ChromeOptions()
options.add_argument("--start-maximized")
options.add_argument('window-size=2560,1440')
driver = webdriver.Chrome(chrome_options=options)

You can also edit the window size as you prefer. The information on this website might also come in handy: http://selenium-python.readthedocs.io

reincore
  • 345
  • 5
  • 11
4

driver.maximize.window() did not work for me.

This worked.

browser.maximize_window()
4b0
  • 21,981
  • 30
  • 95
  • 142
CodingMatters
  • 1,275
  • 16
  • 26
0

You can use below code to maximize the browser

driver.maximize.window()
Hassan Imam
  • 21,956
  • 5
  • 41
  • 51