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

后端 未结 17 2211
小蘑菇
小蘑菇 2021-01-31 15:53

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

相关标签:
17条回答
  • 2021-01-31 16:45

    In OSX Mavericks you can assign destop from the Options menu when clicking and holding the icon from the dock. This solved the problem for me.

    0 讨论(0)
  • 2021-01-31 16:46

    use this condiction:

    WebDriver chrome1 = new ChromeDriver();
    WebDriver chrome2 = new ChromeDriver();
    
    chrome1.manage().window().maximize();//display 1
    
    chrome2.manage().window().setPosition(new Point(2000,0));//display 2
    Thread.sleep(1000);// 1 sec
    chrome2.manage().window().maximize();//maximize display 2
    
    0 讨论(0)
  • 2021-01-31 16:49

    I have noticed that by setting these things below, my browser gets opened alway in the same monitor (I have two monitors the eDP and a secondary HDMI monitor). Maybe it has to do with the position:

    # console log
    d = desired_capabilities.DesiredCapabilities.CHROME
    d['loggingPrefs'] = { 'browser':'ALL' }
    
    # Driver
    self.driver = webdriver.Chrome(desired_capabilities=d)
    self.driver.implicitly_wait(5) # seconds
    self.driver.set_window_size(800, 800)
    self.driver.set_window_position(0, 0)
    
    0 讨论(0)
  • 2021-01-31 16:50

    For Java:

    //imports:
    import java.awt.*;
    import java.awt.event.InputEvent;
    
    driver = new FirefoxDriver();
    
    //drag & drop to my right screen in debug mode:
    boolean isDebug = java.lang.management.ManagementFactory.getRuntimeMXBean().getInputArguments().toString().indexOf("jdwp") >= 0;
    
    if(isDebug) {
      Robot robot = new Robot();
    
      robot.mouseMove(800, 10);
      robot.mousePress(InputEvent.BUTTON1_MASK);
      robot.mouseMove(2800, 100);
      robot.mouseRelease(InputEvent.BUTTON1_MASK);
      driver.manage().window().maximize();
    }
    

    driver.manage().window().setPosition(point); didn't work for me.

    0 讨论(0)
  • 2021-01-31 16:52

    If you are running Windows 7 or later, you can (hack-ishly) achieve this by setting the desired display as your main display under "Change Display Settings". Any new browser windows will now open in this one. Keep in main that this of course affects your toolbar etc, which may or may not be annoying. It is certainly less annoying than having browser windows thrown in your face on a steady basis.

    0 讨论(0)
  • 2021-01-31 16:53

    It is very useful for debugging to run tests on a secondary monitor. Unfortunately you cannot specify on which monitor browser should be opened. The options are:

    1. Open browser and drag it to the desired monitor, then close it. Next time it will be opened on that monitor
    2. Use software like Ultramon to control on which monitor to start browser.

    Also you can use a virtual machine that will be run on the second monitor - just drag it there.

    0 讨论(0)
提交回复
热议问题