How to Manage Browser Dimension and Position in Selenium Webdriver

Sometimes you need to set Dimension and Position of your browser window. Webdriver have built in Dimension and Position class with many different methods. We can use both these class and it's methods to set dimensions and positions of browser window. Let's see how we can use Dimension and Position methods to manage size and position

How to manage Browser Dimension and Position?
package TestPack;

import org.openqa.selenium.Dimension;
import org.openqa.selenium.Point;
import org.openqa.selenium.WebDriver;

public class testSetPosition {

 public static void main(String[] args) {
  String exePath = "D:\\chromedriver_win32\\chromedriver.exe";
  System.setProperty("", exePath);
  WebDriver driver = new ChromeDriver();
  //Set browser window width and height to 300
  Dimension dim = new Dimension(300, 300);
  //Set window position from top left corner of screen.
  Point pnt = new Point(100, 100); 

Maximize and Full screen Window using manage() method in Selenium WebDriver

In above example, We have defined Dimension 300H and 300W and then used setSize() method to set given dimension for browser window. Same way, We have defined 100 points from top and 100 points from left side of screen and then used setPosition method to set browser window at given position.

No comments:

Post a comment