How to maximize and minimize browsers in Selenium with python?


We can maximize and minimize the browser while we are testing an application in Selenium.

For maximizing the browser, maximize() method is to be used.

For minimizing the browser, minimize() method is to be used.

Both these methods can be used simultaneously in the same program.

Example

Code Implementation

from selenium import webdriver
#browser exposes an executable file
#Through Selenium test we will invoke the executable file which will then #invoke actual browser
driver = webdriver.Firefox(executable_path="C:\geckodriver.exe")
# to maximize the browser window
driver.maximize_window()
#get method to launch the URL
driver.get("https://www.tutorialspoint.com/index.htm")
#to refresh the browser
driver.refresh()
# to minimize the browser window
driver.minimize_window()
#to close the browser
driver.close()

Updated on: 29-Jul-2020

2K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements