Tuesday, 9 February 2016

How to set browser width and height in Selenium Webdriver

How to set browser width and height in Selenium Webdriver:
===============================================
When ever based on your requirement if we want we can change the width and height of the browser in selenium.

Selenium provided one predefined class called Dimension,by using class we can set the width and height of the browser

Syntax:
----------
Dimension dimension = new Dimension(int width, int height);
Dimension dimension = new Dimension(500, 800);

//eaxmple on how to set width and height of the browser in selenium
------------------------------------------------------------------------------------------
package blog;

import java.util.concurrent.TimeUnit;

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

public class SetWidthDemo {

public static void main(String[] args) {

WebDriver webDriver = new FirefoxDriver();

webDriver.manage().timeouts().implicitlyWait(45, TimeUnit.SECONDS);

webDriver.manage().deleteAllCookies();

webDriver.navigate().to("http://google.co.in");

webDriver.manage().window().getSize();

System.out.println(webDriver.manage().window().getSize());

Dimension dimension = new Dimension(500,800);

webDriver.manage().window().setSize(dimension);

webDriver.quit();

}

}

No comments:

Post a Comment