Maximize window with selenium in C#

There is more than one way to maximize your browser window with selenium webdriver in C sharp.. In previous versions of webdriver these methods where not standardized over different browsers. Allthough Firefox and Internet Explorer would behave in the same manner, Google Chrome on the other hand would not work differently (selenium 2). As an alternative you can however use a javascript command:

    MyDriver.Navigate().GoToUrl("https://www.somesite.be/");
((IJavaScriptExecutor)MyDriver).ExecuteScript("window.resizeTo(1920, 1080);");

In newer versions of selenium webdriver for chrome (selenium 3), the library is managed by Google and you can expect it to work properly.

If you want to start your window maximized, use the following command:

ChromeOptions MyOptions = new ChromeOptions();
MyOptions.addArgument("--start-maximized");
MyDriver = new ChromeDriver(MyOptions);

An even simpler approach is to use a webdriver built-in action:

MyDriver.Manage().Window.Maximize();

In this approach you may have to set the position of the browser before maximizing:

MyDriver.Manage().Window().setPosition(new Point(0,0));