Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selenium-opening browser in different screen

I am trying to open Selenium in a different screen rather than the main screen and in maximum size. I tried

browser.set_window_position(2000, 0)
browser.maximize_window()

But it opens the browser in main window first and then moves it to the different window. I found the following command in

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

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);

But it is in c#. Can anybody please help me out with the python version of it?

like image 274
Krishna Avatar asked Oct 22 '25 19:10

Krishna


1 Answers

use Chrome Options to set the defaults

from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_argument("--window-position=2000,0")
driver = webdriver.Chrome(chrome_options=chrome_options)

There are various options you can add like chrome_options.add_argument("--start-maximized");

like image 85
Ywapom Avatar answered Oct 25 '25 06:10

Ywapom



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!