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

后端 未结 17 2446
小蘑菇
小蘑菇 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:57

    There's actually a fairly easy way to do this. There's a method called 'set_window_position' which accepts negative values. So I wanted the browser to open on my left screen, so a simple negative 1000px pixels dragged it in enough for the maximize_window to pick the left screen.

    driver.set_window_position(-1000, 0)
    driver.maximize_window()
    

    So depending on the screen sizes and where you want it to go, make some calculations and just drag it there!

    Source: http://selenium-python.readthedocs.io/api.html#module-selenium.webdriver.firefox.webdriver (picked firefox for this example)

提交回复
热议问题