Set Browser Width and Height in Selenium Webdriver


Selenium WebDriver allows resizing and maximizing window natively from its API. We use ‘Dimension’ class to resize the window.

Lets take the help of Selenium WebDrivers Dimension Class and declare object say ‘d’ by initializing it with width and height as 420X600 as shown below:

Remember, We need to import the statement ‘import org.openqa.selenium.Dimension’

import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;
public class browser {

@Test
public void openBrowserwithGivenDimension()
{

WebDriver driver = new FirefoxDriver();
driver.navigate().to(“http://google.co.in”);
System.out.println(driver.manage().window().getSize());
Dimension d = new Dimension(420,600);
//Resize the current window to the given dimension
driver.manage().window().setSize(d);
}
}

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s