Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

People also ask

What is the Selenium command to maximize the browser window?

1. Use the maximize() method from WebDriver. Window Interface.

How maximize screen using Selenium?

To maximize browser in Selenium, you need to call the maximize() Selenium command to maximize window interface of the driver class. void maximize() – This method is used to maximize the current browser. You can customize the size of the browser according to the requirement of the scenario.

How do I open Selenium browser full screen?

Same as pressing F11.


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

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

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