Minimize Browser Window

To minimize browser window programmatically using Selenium in Java, use WebDriver.manage().window().minimize() function.

WebDriver.manage().window().minimize() minimizes the current browser window.

The following is a simple code snippet to initialize a web driver and minimize the window.

</>
Copy
WebDriver driver = new ChromeDriver();
driver.manage().window().minimize();

Example

In the following program, we write Selenium Java code to initialize Chrome web driver, get a URL, and minimize the window.

Java Program

</>
Copy
import org.openqa.selenium.*;
import org.openqa.selenium.chrome.ChromeDriver;

public class MyAppTest {
	public static void main(String[] args) {
		//initialize web driver
		System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");
		WebDriver driver = new ChromeDriver();
		
		try {
			//get the URL
			driver.get("https://www.tutorialkart.com/");
			//minimize browser window
			driver.manage().window().minimize();
		} finally {
			driver.quit();
		}
	}
}