How to Set and Get Window size/position using Selenium Webdriver

Author - Webner

How to Set and Get Window size/position using Selenium Webdriver

In website testing, most of the time, we need to set window position and size or get window size and position to test the website responsiveness. Selenium Webdriver has many applicable methods using which we can resize a web browser window for a different purpose. One of them is window().maximize(); which we can utilize to maximize the browser window size. Selenium Webdriver also has methods to set and get the window size and position.

Here are the methods:

Method to set the window height and width:
driver.manage().window().setSize(new Dimension(width, height));

Method to get the window height:

Method to get the window width:

Method to set the window position:
driver.manage().window().setPosition(new Point( x coordinate, y coordinate));

Method to get the window position of the X coordinate:

Method to get the window position of the Y coordinate:


package Testing;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import io.github.bonigarcia.wdm.WebDriverManager;
public class windowSize {
WebDriver driver;
public void setup() throws Exception {
driver = new ChromeDriver();
public void setWindowSize(){
//Set size method used to set window size width and height.
driver.manage().window().setSize(new Dimension(400,600));
//Get size method used to get window width and height.
int windowHeight = driver.manage().window().getSize().getHeight();
int windowWidth = driver.manage().window().getSize().getWidth();
System.out.println("Window height is "+ windowHeight);
System.out.println("Window width is "+ windowWidth);
public void setWindowPosition() throws InterruptedException{
//Set position method used to set window position on the x coordinate and y coordinate.
driver.manage().window().setPosition(new Point(100,100));
//WebDriver getPosition method used to get window position x,y coordinates.
int X = driver.manage().window().getPosition().getX();
int Y = driver.manage().window().getPosition().getY();
System.out.println("Window position X coordinates is "+ X);
System.out.println("Window position Y coordinates is "+ Y);
public void closeWindow() throws InterruptedException{



Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *