Set browser’s height and width using Selenium

Set browser’s 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.

Code snippet to resize 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). 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);

Please comment below to share your views or ask any questions. Also, share this post on social media with your friends, and don’t forget to check our complete selenium tutorial here.

Selenium Tutorial

От QA genius

Adblock
detector