Saturday, September 15, 2012

How to maximize window size of current window using webdriver?

How to maximize window size of current window  using webdriver?

Generally when we start the browsers, it will open based on its previous state. Some times it is customized to certain size (width and height) manually. So in order to make the browser opens in a maximized window, we need to use Toolkit class.

Maximize window option will allows the user to see the complete application under test.

Here is the snippet to achieve the maximized window using Webdriver...

Here driver is WebDriver object for Firefox or IE driver.

WebDriver driver = new Firefoxdriver();

public static void maximizeWindow(){
        Toolkit t = Toolkit.getDefaultToolkit();
        org.openqa.selenium.Dimension screenResolution = new org.openqa.selenium.Dimension((int)t.getScreenSize().getWidth(), (int)t.getScreenSize().getHeight());
        driver.manage().window().setSize(screenResolution);
   
    }

No comments:

Post a Comment