How to Manage Browser Dimension and Position in Selenium Webdriver

Sometimes you need to set Dimension and Position of your browser window. We have built in selenium dimension class and selenium Position class with many different methods. We can use dimension class in selenium and Position class in selenium 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

Selenium dimension class and Selenium Position calss 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();
  //Selenium Dimension Class Set browser window width and height to 300
  Dimension dim = new Dimension(300, 300);
  //Selenium Position Class to 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 Selenium Dimension and Selenium Position 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