My Thoughts: Maximize browser window using webdriver

Saturday, January 5

Maximize browser window using webdriver

There are times when we want to to maximize the browser window during the execution of our script .For this purpose webdriver providers a built-in method and here is the syntax :

WebDriver driver;

Here is the sample code using TestNG framework. :
import java.awt.Toolkit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Reporter;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

public class MaximizeWindow {

WebDriver driver;

public void setUpDriver() {
driver = new FirefoxDriver();

public void maximize() {
 //declare varibales for windows
org.openqa.selenium.Dimension defaultDim;
org.openqa.selenium.Dimension maximizeDim;
//Load google website on browser
//Display the current screen dimensions
System.out.println("screenHeight before maximizing"+defaultDim.getHeight());
System.out.println("screenWidth before maximizing"+defaultDim.getWidth());
//maximize the window using webdriver method
//Display the maximized window dimensions
System.out.println("screenHeight after maximizing:"+maximizeDim.getHeight());
System.out.println("screenWidth after maximizing:"+maximizeDim.getWidth());


Last but not the least

Belated Happy New Year All..!!

Have fun..!! :)

1 comment:

  1. Madiraju Krishna ChaitanyaMonday, July 14, 2014

    Hi Vamsi Kurra Ji,Thanks a LOT for this content.