5

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}
3

3 Answers 3

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

Sign up to request clarification or add additional context in comments.

Comments

5

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

This worked.

browser.maximize_window()

Comments

0

You can use below code to maximize the browser

driver.maximize.window()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.