Is there a way to set the initial browser location using selenium?

yahoo2344 :

We are developing a web page automation program. I'd like to control where the webpage runs. This code moves the browser to a location after a certain amount of time. I want to move my browser right away from the program. How do you have? The driver uses a chrome driver.

driver.manage().window().setPosition(new Point(200,0));
AndiCover :

Set the position of the browser window right after initializing the driver. Your code would then look like:

WebDriver driver = new RemoteWebDriver(); //or whatever implementation you use
driver.manage().window().setPosition(new Point(200, 0));

It is possible to move the browser to another monitor. For example you have two monitors with a resolution of 1920x1080 then you need to set the X-axis to >= 1920. Then you can maximize the window:

driver.manage().window().maximize();

Note: On a Windows system the X-axis depends on your main monitor (Right click on Desktop -> Display settings -> select one monitor and see which one has the checkbox "Make this my main display" ticked.

An example: You have a three monitor setup and your main monitor is in the center. To move your browser to the right screen you need Point(1920, 0) and to move it to the left screen you need Point(-1920, 0).

On MacOS this does not work because the main monitor is always the last selected one (mouse click).

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=357370&siteId=1
Recommended