11/23/17

How To Resize Browser Window Using Selenium WebDriver


To resize browser window to particular dimensions, we use ‘Dimension’ class to resize the browser window.

The below code opens the pavantestingtools.com blog and then set the browser window size to 480*620 .
import org.openqa.selenium.Dimension;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ResizeBrowser {

public static void main(String args[]) {
System.setProperty("webdriver.gecko.driver", "C://Drivers//geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.navigate().to("http://www.pavantestingtools.com");
System.out.println(driver.manage().window().getSize());
// Create object of Dimensions class
Dimension d = new Dimension(480, 620);
// Resize the current window to the given dimension
driver.manage().window().setSize(d);
System.out.println(driver.manage().window().getSize());
}
}

0 comments:

Post a Comment