How to Maximize window in chrome using webDriver (Python)?

SeleniumAutomation TestingTesting Tools

We can maximize windows on Chrome with a webdriver. While working on any automated test cases, if the browser opens in maximized mode then the probability of the scripts getting failed lessens.

This is because if the element is visible, then the chances of its interaction increases. Also, if the window is maximized, then the testers or developers working on them gets a better visibility of the test steps.

Some of the applications open in maximized mode automatically. Applying maximizing techniques on them does not have any impact on them. Let us see the methods with which we can maximize window in chrome in python −

  • Using maximize_window() method.

  • Using fullscreen_window() method.

Example

Code Implementation with maximize_window().

from selenium import webdriver
driver = webdriver.Chrome (executable_path="C:\\chromedriver.exe")
# maximize with maximize_window()
driver.maximize_window()
driver.get("https://www.tutorialspoint.com/index.htm")
driver.quit()

Example

Code Implementation with fullscreen_window().

from selenium import webdriver
driver = webdriver.Chrome (executable_path="C:\\chromedriver.exe")
# maximize with maximize_window()
driver.fullscreen_window()
driver.get("https://www.tutorialspoint.com/index.htm")
driver.quit()

So in the above code implementations we have done the following steps −

  • Launched the Chrome browser.

  • Opened an URL.

  • Maximized the Chrome browser.

  • Quitted the driver session.

raja
Published on 28-Aug-2020 12:29:47
Advertisements