maximize and minimize browser in selenium

Maximize or Minimize a browser

Last updated on

When we launch a browser using Selenium WebDriver, by default it is not in its maximized state. In this post, we will see how to maximize and minimize a browser during automation.

Maxmize a browser

During automation, it’s one of the best practices to maximize the browser in the initial phases (or in the @BeforeTest method in case you are using TestNG as the testing framework). The following command can be used to maximize the browser window.

driver.manage().window().maximize();


Minimize a browser

Unfortunately, Selenium WebDriver doesn’t provide any native support for minimizing a browser. If we don’t want to see the browser in action during automation than we can use Headless browsers like HTMLUnitDriver, PhantomJS, etc. But in case we specifically want to minimize a browser during automation than we can make use of the below statement. The following code snippet will position the browser to an area that is not within the viewable section of the machine we are working on. Thus making it appear as if the browser window got minimized.

driver.manage().window().setPosition(new Point(0, -1000));

That’s all we have in this post, comment below if you have any queries. Also please share this post with your friends and don’t forget to check our complete selenium tutorial here.

Selenium Tutorial

1 thought on “Maximize or Minimize a browser”

Leave a Comment