How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#?

Java

driver.manage().window().maximize();

Python

driver.maximize_window()

Ruby

@driver.manage.window.maximize

OR

max_width, max_height = driver.execute_script("return [window.screen.availWidth, window.screen.availHeight];")
@driver.manage.window.resize_to(max_width, max_height)

OR

target_size = Selenium::WebDriver::Dimension.new(1600, 1268)
@driver.manage.window.size = target_size

driver.Manage().Window.Maximize();

This works for IE and Firefox. Chrome does not work. There is a bug submitted for this on ChromeDriver project.

Meanwhile, the get around for the chrome is to implement what Joey V. and Coder323 suggested.

ChromeOptions options = new ChromeOptions();
options.addArgument("--start-maximized");
driver = new ChromeDriver(options);

For IE and Firefox:

driver.manage().window().maximize();

For Chrome:

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
driver = new ChromeDriver( options )

There's an outstanding issue to add this functionality to WebDriver, which can be tracked here: http://code.google.com/p/selenium/issues/detail?id=174

A workaround would be to use the JavascriptExector as follows:

public void resizeTest() {
    driver.Navigate().GoToUrl("http://www.example.com/");
((IJavaScriptExecutor)driver).ExecuteScript("window.resizeTo(1024, 768);");
}