Here is what we cover:

Why Maximize a Browser in Selenium Automation?
How to Maximize Window in Selenium Example: Resize a browser using selenium web driver Example: Maximize a browser window using web driver.
Example: Minimize a browser window using web driver.

Why Maximize a Browser in Selenium Automation?

Elements on the web application may not be recognized by the selenium if the browser is not maximized and thereby making framework fail. Hence, Maximize the browser is very important part of selenium framework. It is good practice to maximize the browser while automating any web application. When the user executes the selenium framework or any script, browser may not be in the full screen state and you need to maximize the browser using window maximize in Selenium to view all the elements of the web application. It is good to maximize the browser at the start of the script, so that the script gets executed successfully without any error.

Summary

In the above tutorial , we illustrate the resizing of the browser through different scenarios like to maximize, minimize and resize as required in the project framework for different functionality.

In the first scenario , we have shown the resize of the browser in selenium.

Dimension d = new Dimension(300,1080); driver.manage().window().setSize(d);

In the second scenario, we have shown the Selenium maximize window of the browser.

driver.manage().window().maximize();

In the third scenario, we have shown the minimize of the browser in selenium.

Point p = new Point(0,3000); driver.manage().window().setPosition(p);

To maximize browser in Selenium, you need to call the maximize() Selenium command to maximize window interface of the driver class.

You can customize the size of the browser according to the requirement of the scenario. Selenium webdriver does not provide any method for minimizing the browser, there is no such direct method. You need to use resize method to minimize the browser.

Example: Resize a browser using selenium web driver

a) Selenium script with explanation.

Script Description : In the below Selenium script shown the resize of the browser using testNG framework , steps of the scenario are :

Open the chrome browser . Launch the site . Wait for a few seconds as to view the resize action . Close the browser.

b) Output Analysis

    Opened the chrome browser , resized the browser, wait for a  few seconds and closed the browser.

Example: Maximize a browser window using web driver.

a) Selenium script with explanation.

Script Description : In the below maximize in Selenium script shown, the maximization of the browser using testNG framework, steps of the scenario for maximize window Selenium are :

Open the chrome browser . Launch the site . Wait for a few seconds as to view the browser maximize in Selenium action . Close the browser.

b) Output Analysis

Opened the chrome browser , maximized the browser, wait for a few seconds and closed the browser.

Example: Minimize a browser window using web driver.

a) Selenium script with explanation.

Script Description : In the below Selenium script shown the minimize of the browser using testNG framework , steps of the scenario are :

Open the chrome browser . Launch the site . Wait for a few seconds as to view the minimize action . Close the browser.

Note: If the user wants to use Firefox browser, then user needs to set property of FirefoxDriver and create FirefoxDriver object instead of ChromeDriver in all above 3 scenarios scripts as given below:

b) Output Analysis

Opened the chrome browser , minimized the browser, wait for a few seconds and closed the browser.

TroubleShooting

Use the latest versions of Selenium Jars, chromedriver, marionette driver and IEdriver etc. Check the compatibility of the selenium jars and browser used.