How to open webdriver multiple chrome driver in different position of monitor?

2.9k views Asked by At

I have a test in webdriver that open multiple chrome browser at same time but when it opens it overlap with each other. But I would like to open them without overlapping each other in same monitor. Is this possible, cannot find anything specific?

Let me know if there is any method for in webdriver to perform this action.

Thank you

1

There are 1 answers

1
Tom Trumper On

Whilst WebDriver does not have a specific convenience method to do what you are asking for, you can approach the issue programmatically by determining the height/width of your monitor and setting the size and position of your windows accordingly.

Below is an example of how you could implement this to display two windows side by side using Selenium libraries:

    //Maximise the window size to determine the height and width available
    driver.manage().window().maximize();

    //Retrieve the size of the maximised window as a dimension
    Dimension windowSize = driver.manage().window().getSize();

    //Determine the desired height and width of the window and store it as a dimension
    int desiredHeight = windowSize.height;
    int desiredWidth = windowSize.width/2;   //Half the screen width
    Dimension desiredSize = new Dimension(desiredWidth, desiredHeight);

    //Set the size of the window to the dimension determined above
    driver.manage().window().setSize(desiredSize);

    //Set the position of the window relative the upper left corner of the screen
    driver.manage().window().setPosition(new Point(0, 0));            //Left side of screen
    //OR
    driver.manage().window().setPosition(new Point(targetWidth, 0));  //Right side of screen