Maximizing the browser window

Selenium RC's windowMaximize() command was missing in Selenium WebDriver. However, starting from release 2.21, Selenium WebDriver supports maximizing the browser window.

In this short recipe, we will see how to maximize the browser window.

Getting ready

Create a new test that will get an instance of WebDriver, navigate to a site, and perform some basic actions and verifications.

How to do it...

To maximize a browser window, we need to call the maximize() method of the Window interface of the driver class. Add the second line of code from the following code; this is where you define an instance of FirefoxDriver:

driver = new FirefoxDriver();
driver.manage().window().maximize();

Get Selenium Testing Tools Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.