resize browser window in selenium

Resize Browser Window in Selenium

Last updated on

Set Browser Height and Width using Selenium

At times during automation, we may be required to test an application with some specific browser window dimensions. In this post, we will be studying how to resize a browser to an exact dimension.

In order to achieve this, we will use the setSize() method which takes the Dimension object as input. The Dimension object has width and height integer fields. Hence, we can set the width and height of the browser by calling the setSize method with the required dimensions of the browser window.

Advertisement

Code Snippet to Resize Browser Window in Selenium

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). Selenium provides a direct command to maximize the browser window. The following command is used to maximize the browser window.

int width = 600;
int height = 400;
Dimension dimension = new Dimension(width, height);
driver.manage().window().setSize(dimension);

This completes our tutorial on Resize browser window in Selenium. Please comment below to share your views or ask any questions. Don’t forget to check our complete selenium tutorial here.

Selenium Tutorial

Advertisement

1 thought on “Resize Browser Window in Selenium”

Leave a Comment