воскресенье, 4 ноября 2012 г.

Maximize browser window in Selenium Web Driver(how to get full screen in selenium webdriver)

Maximize browser window in Selenium Web Driver(3 ways how to get full screen in selenium webdriver)

1) The very first method which is given in their documentation is using maximize() command of selenium instance:

public static void main(String[] args) {

 // Create a new instance of the Firefox driver
 WebDriver driver = new FirefoxDriver();

  // And now use this to visit Google
 driver.get("http://www.google.com");

 // Maximize browser window
 driver.manage().window().maximize();

}

2)  Maximize the browser window according to your system's current resolution using the toolkit utility which query the native operating system directly and is platform independent:

public static void main(String[] args) {

 // Create a new instance of the Firefox driver
 WebDriver driver = new FirefoxDriver();

  //Set the upper left corner of the screen starting point
   driver.manage().window().setPosition(new Point(0,0));

  //define screen size
   java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();

  // define desired size
   Dimension maxWindowSize = new Dimension((int) screenSize.getWidth(), (int) screenSize.getHeight());

  // Maximize the browser window according to your system's current resolution(set desired size)
 driver.manage().window().setSize(maxWindowSize);

}

3) Third method emulate enter to fullscreen mode, same as pressing F11:

public static void main(String[] args) {

 // Create a new instance of the Firefox driver
 WebDriver driver = new FirefoxDriver();

  // And now use this to visit Google
 driver.get("http://www.google.com");

 // Find the body and then send F11
 driver.findElement(By.tagName("body")).sendKeys(Keys.F11);

}

   

4 комментария: