How to maximize or minimize a browser window using Selenium webdriver with Python?

SeleniumSoftware TestingTesting Tools

We can maximize or minimize a browser window using Selenium webdriver in Python. We can use the method maxmize_window to maximize a browser.

We can use the method minimize_window to minimize a browser. Finally, Again, to get the size of the browser, we can use the method get_window_size.

Syntax

driver.maximize_window()
driver.minimize_window()

Example

Code Implementation

from selenium import webdriver
#set geckodriver.exe path
driver = webdriver.Firefox(executable_path="C:\geckodriver.exe")
#implicit wait
driver.implicitly_wait(5)
#launch URL
driver.get("https://www.tutorialspoint.com/index.htm")
#maximize browser
driver.maximize_window()
#minimize browser
driver.minimize_window()
#quit browser
driver.quit()
raja
Updated on 18-Nov-2021 12:10:24

Advertisements