Maximize Browser Window

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

WebDriver.manage().window().maximize() maximizes the current window if it is not already maximized.

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

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

Example

In the following program, we write Java code to initialize a web driver, maximize the window, and open a URL.

Java Program

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

public class MyAppTest {
    public static void main(String[] args) {
        System.setProperty("webdriver.chrome.driver", "/usr/local/bin/chromedriver");  
    	WebDriver driver = new ChromeDriver();
        driver.get("https://www.google.com/ncr");
    	driver.manage().window().maximize();
        driver.quit();
    }
}

Screenshots

1. Initialize web driver and navigate to google.com.

2. Maximize window.