Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In a multi-monitor display environment, how do I tell Selenium which display to open a new window in?

Tags:

selenium

Sorry if this has been asked and answered. I did a search but came up empty.

like image 230
Mike Jr Avatar asked Sep 28 '10 18:09

Mike Jr


People also ask

How do I open the browser window in selenium?

Open a New Tabget('https://selenium.dev'); // A new tab is opened and switches to it await driver. switchTo(). newWindow('tab'); // Loads Sauce Labs open source website in the newly opened window await driver.

How do I check my window screens?

Select Start > Settings > System > Display. Your PC should automatically detect your monitors and show your desktop. If you don't see the monitors, select Detect.


2 Answers

In python:

browser = webdriver.Chrome() browser.set_window_position(2000, 0) 
like image 79
wailord Avatar answered Sep 23 '22 02:09

wailord


Two options (this is for the coypu c# wrapper):

  1. 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); 
  2. 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)   {   } } 
like image 27
mstrange Avatar answered Sep 23 '22 02:09

mstrange