Selenium Set Window Size

Set browser window size in selenium

Selenium has built in method to set size of browser window. You can use setSize() method to set the browser window size during your selenium test execution. This method is useful when you want to resize the browser window as per your selenium test requirement.
  • setSize() method is part of WebDriver.Window interface.
  • This method's return type is void.
  • You can provide the size of window to set set size of current working window in selenium test.
  • Syntax : driver.manage().window().setSize(new Dimension(w, h));
  • It will set window size as per the given dimension.
selenium setsize method

Let us implement this method practically to see how it works.

setSize() example in selenium

package testPackage;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;

public class setsizeExample{

	public static void main(String[] args) {
		System.setProperty("", "D:\\chromedriver.exe");
		WebDriver driver=new ChromeDriver();		
		//Set size of browser window as per given dimensions.	
		driver.manage().window().setSize(new Dimension(1250, 600));

If you look at above given example, We have provided window size dimension to 1250 X 600. It will set browser window size as per provided dimensions.

No comments:

Post a Comment