Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
513 views
in Technique[技术] by (71.8m points)

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

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

question from:https://stackoverflow.com/questions/3816073/in-a-multi-monitor-display-environment-how-do-i-tell-selenium-which-display-to

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Two options (this is for the 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)
  {
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...