Selenium Maximize Window Of Browser

Maximize window in selenium

You can maximize window in selenium using maximize() method. Every time you launch browser in selenium test, It will open browser window in small size. So maximize() is most commonly used method in selenium test scripts. Maximize() method works same as user click on browser maximize icon to maximize the window. Selenium test scripts can be run without maximizing windows as well but it is good practice to maximizing browser windows before running the tests on page.

selenium maximize() method
  • Maximize() method in selenium is part of WebDriver.Window interface.
  • It's return type is void.
  • It will maximize the current working browser window if it is not already maximized.
  • This method is generally used just after launching the browser window in selenium test script.
  • Syntax : driver.manage().window().maximize();
Let us see practical example to maximize the browser window in selenium test.

Selenium window maximize() example

package testPackage;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;

public class maximizewindowExample {

	public static void main(String[] args) {
				
		System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
		WebDriver driver=new ChromeDriver();
		//Maximize the browser window.
		driver.manage().window().maximize();
		
		driver.navigate().to("http://only-testing-blog.blogspot.com/2013/09/testing.html");
	}
}

In above given example, we have used maximize() method after launching the browser. So initially browser will be launched and then maximize() method will maximize the browser window.

No comments:

Post a Comment