Sorry if this has been asked and answered. I did a search but came up empty.
Wailord's answer worked for me but it always opened the window and then moved it. So there is a brief moment where it blocks my editor.
Chrome has a command-line switch for window position
--window-position=x,y
https://peter.sh/experiments/chromium-command-line-switches/#window-position
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument('window-position=2000,0') # opens at x=2000,y=0 from the start
driver = webdriver.Chrome(options=options)
I use this not very fancy, but quick method to achieve that. Because I do not only want it on my second screen but also maximized I don't have to be too precise on the coordinates. Any X-coordinate above 2000 is usually on the second screen for all my dev machines: (This example uses chromedriver but works with any IWebDriver)
chrome = new ChromeDriver();
chrome.Manage().Window.Position = new System.Drawing.Point(2000, 1); // To 2nd monitor.
chrome.Manage().Window.Maximize();
Two options (this is for the coypu c# wrapper):
Use the Selenium Driver's window positioning commands:
var monitor = Screen.FromPoint(new Point(Screen.PrimaryScreen.Bounds.Right + 1, Screen.PrimaryScreen.Bounds.Top));
var seleniumDriver = new ChromeDriver(options);
seleniumDriver.Manage().Window.Position = new Point(monitor.Bounds.X, monitor.Bounds.Y);
var coypuDriver = new MultimonWebDriver(seleniumDriver, Browser.Chrome);
var rv = new BrowserSession(sessionConfiguration, coypuDriver);
Configure the Driver with a command line argument. I prefer this because solution #1 causes a flicker from the driver's server showing the window before processing the move command:
var monitor = Screen.FromPoint(new Point(Screen.PrimaryScreen.Bounds.Right + 1, Screen.PrimaryScreen.Bounds.Top));
var options = new ChromeOptions();
options.AddArgument(String.Format("--window-position={0},{1}", monitor.Bounds.X, monitor.Bounds.Y));
var seleniumDriver = new ChromeDriver(options);
var coypuDriver = new MultimonWebDriver(seleniumDriver, Browser.Chrome);
var rv = new BrowserSession(sessionConfiguration, coypuDriver);
where MultimonWebDriver is simply exposing access to the protected constructor:
public class MultimonWebDriver : SeleniumWebDriver
{
public MultimonWebDriver(IWebDriver webDriver, Browser browser) : base(webDriver, browser)
{
}
}
In python:
browser = webdriver.Chrome()
browser.set_window_position(2000, 0)
My solution is install an VNC server, open the VNC in one of the monitors and launch selenium through the VNC. Then you have always one monitor for the browsers of selenium without the annoying windows opened each time a test is launched
On Mac you can control this in System Preferences > Displays > Arrangement
There is a white bar at the top of the primary screen. Drag it to the screen where you want the browsers to be rendered