Skip to content

Make Selenium Easy

And Keep It That Way

  • Home
  • Share
  • Toggle search form

Now You Can Minimize Browser in Selenium WebDriver

Posted on 02/19/2025 By admin

Till Selenium 3, we were only able to maximize the window. We were not able to minimize directly. There were ways to do like setPosition() but it was of no use if you can not maximize whenever you want.

Selenium 4 gives you a brand new method named “minimize()” which can be used to minimize the browser just like a user normally do. “minimize” method is in inner interface “Window” of WebDriver interface.

Return type of minimize() method is void and official doc says it ” Minimizes the current window if it is not already minimized “.

Syntax :-

Same as maximize. Just use minimize in stead of miximize.

driver.manage().window().minimize();

Remember to use this method you need to have Selenium 4.0.0-alpha-5 in build path as it is launched in that particular version onward.

It takes screenshot also without any problem.

Sample Program :-

package SeleniumFourFeatures;

import java.io.File;
import java.io.IOException;

import org.openqa.selenium.By;
import org.openqa.selenium.OutputType;
import org.openqa.selenium.TakesScreenshot;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;

import com.google.common.io.Files;

import io.github.bonigarcia.wdm.WebDriverManager;

public class MinimizeExample {
        
        @Test
        public void doActions() throws IOException {
                
                WebDriverManager.chromedriver().setup();
                WebDriver driver = new ChromeDriver();
                
                driver.get("http://automationpractice.com/index.php?controller=authentication&back=my-account");
                
                // Minimize browser
                driver.manage().window().minimize();
                
                // Locating Email Address field
                WebElement emailAddress = driver.findElement(By.id("email_create"));
                
                // Let's perform same actions multiple times.
                emailAddress.sendKeys("[email protected]");
                emailAddress.clear();
                emailAddress.sendKeys("[email protected]");
                emailAddress.clear();
                emailAddress.sendKeys("[email protected]");
                emailAddress.clear();
                
                // Let's refresh the web page
                driver.navigate().refresh();
                
                // Relocating web element
                emailAddress = driver.findElement(By.id("email_create"));
                
                emailAddress.sendKeys("[email protected]");
                // Taking screenshot 
                TakesScreenshot ts = (TakesScreenshot)driver;
                File ss = ts.getScreenshotAs(OutputType.FILE);
                File ds = new File(System.getProperty("user.dir")+"/src/test/resources/screenshot.png");
                Files.copy(ss, ds);
                
                emailAddress.clear();
                
                driver.close();
                
                
        }

}

You will see browser will be minimized and execution will be finished silently and you can do you other works. You can see taken screenshots in resource. Cool feature. Thanks developers of Selenium WebDriver.

You can find my Selenium WebDriver Java GIT repo here.

If you have any doubt, feel free to comment below.If you like my posts, please like, comment, share and subscribe.#ThanksForReading

#HappyLearning

Uncategorized

Post navigation

Previous Post: TestNG Tutorials 60: Dependency in TestNG – Creating Dependency Among Test Methods – DependsOnMethod
Next Post: #3. OAuth 2.0 Flow – What Is An Access Token?

Related Posts

December 19, 2018 – Make Selenium Easy Uncategorized
Hierarchy of Selenium Classes and Interfaces – Make Selenium Easy Uncategorized
angular-icon-1-logo-png-transparent – Make Selenium Easy Uncategorized
Interview for Automation Testing Profile Uncategorized
Cucumber Tutorial 1 – Setup a Basic Maven-Cucumber 5 -Junit Project in Eclipse Uncategorized
TestNG Tutorials 40: Groups of Groups or MetaGroups in TestNG | Make Selenium Easy Uncategorized

Recent Posts

  • Getting Started with Selenium 4: What Is New and How to Upgrade from Selenium 3
  • Manual Testing
  • Baby Steps To Become Efficient Selenium-Java Automation Tester
  • Features of Selenium 4.0.0 Release – Java Binding
  • Part 1: Handling Drop-down Created Using SELECT Tag In Selenium

Recent Comments

No comments to show.

Archives

  • April 2026
  • April 2025
  • March 2025
  • February 2025
  • January 2025
  • December 2024
  • November 2024
  • October 2024
  • September 2024
  • August 2024
  • April 2024
  • March 2024
  • February 2024
  • December 2023
  • October 2023
  • August 2023
  • November 2022
  • September 2022
  • August 2022
  • July 2022
  • May 2022
  • March 2022
  • October 2021
  • April 2021
  • March 2021
  • January 2021
  • December 2020
  • October 2020
  • September 2020
  • August 2020
  • June 2020
  • May 2020
  • April 2020
  • March 2020
  • February 2020
  • January 2020
  • December 2019
  • November 2019
  • October 2019
  • September 2019
  • August 2019
  • May 2019
  • December 2018
  • November 2018
  • October 2018
  • September 2018
  • August 2018
  • July 2018
  • January 2018

Categories

  • Getting Started
  • Uncategorized

Copyright © 2026 Make Selenium Easy.

Powered by PressBook Masonry Dark