Selenium WebDriver provides built-in functionality for managing the size of browser windows through its Window interface. The current browser window can be expanded to its maximum size using the maximise()
function and it can be shrunk to its lowest size using the minimise()
method.
Maximize and Minimize methods
- void maximize()
- void minimize()
The Selenium WebDriver library provides an interface called Window
that provides the user with the ability to interact with the browser window. This interface includes methods like maximize()
and minimize()
that allows the user to adjust the size of the browser window as needed. The maximize()
method can be used to expand the window to its full size, while the minimize()
method can be used to shrink the window to the smallest possible size. The Window
interface is part of the WebDriver
interface and provides users with an easy and convenient way to manage the browser window size when interacting with web pages.
Maximize Browser Window – Java Code Snippet
driver.manage().window().maximize();
Minimize Browser Window – Java Code Snippet
driver.manage().window().minimize();
Example
package TestAutomationCentral;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MaximizeMinimizeBrowseWindow {
public static void main(String[] args) {
//TestAutomationCentral.com
System.setProperty("webdriver.chrome.driver", "C:\\temp\\drivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.google.com/");
driver.manage().window().maximize(); // maximize the Browser Window
driver.manage().window().minimize(); // minimize the Browser Window
}
}