How to maximize window in Selenium Python

In this post, we will learn How to maximize a browser window in Selenium Python with examples. The Selenium web driver API is used for test automation on Windows or mobile. It helps us remotely control different browsers automatically as if a real user is interacting by stimulating activities like opening or closing a new window, or tab, entering text in the textbox, selecting values from the dropdown, and mouse control.

How to maximize window in Selenium Python

In test automation in selenium, The web application elements or scripts are not identified by the selenium web browser. if the window is not maximized accessing or performing operations on web elements are failed. To avoid this failure maximizing the window is necessary. To load all the elements fully. It is necessary to maximize the window at the start of the selenium script.

The selenium web driver maximize_window() function is used to maximize the window. In this, below example.

  • we have launched the web browser using ChromeDriverManager
  • and maximize the window using the maximize_window() method
  • We navigate to a webpage using a driver. get() method.
from selenium import webdriver
from import ChromeDriverManager
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
print("Navigate to URL  = " + driver.title)