Is there any way to maximize the browser window using WebDriver (Selenium 2) with C#?
This is working fine for me.
Capybara.current_session.driver.browser.manage.window.resize_to(1800, 1000)
I tried many of the answers above, but none work well. My chrome driver version is 2.7 and Iam using selenium-java vesion is 2.9.0. The official document suggests using:
var capabilities = new DesiredCapabilities();
var switches = new List<string>
{
"--start-maximized"
};
capabilities.SetCapability("chrome.switches", switches);
new ChromeDriver(chromedriver_path, capabilities);
The above also does not work. I checked the chrome driver JsonWireProtocol
:
http://code.google.com/p/selenium/wiki/JsonWireProtocol
The chrome diver protocol provides a method to maximize the window:
/session/:sessionId/window/:windowHandle/maximize,
but this command is not used in selenium-java. This means you also send the command to chrome yourself. Once I did this it works.
For me, none of the solutions above worked when working with Selenium Web Driver C# + Chrome:
--start-maximized
- it is ignoredI managed to get it working using InputSimulator:
var inputSim = new InputSimulator();
// WinKey + UP = Maximize focused window
inputSim.Keyboard.ModifiedKeyStroke(VirtualKeyCode.LWIN, VirtualKeyCode.UP);
Simply use Window.Maximize()
command
WebDriver driver= new ChromeDriver()
driver.Manage().Window.Maximize();
For C#:
driver.Manage().Window.Maximize();
For Java:
driver.manage().window().maximize();
For Java:
driver.manage().window().maximize();
It will work in IE, Mozilla, Chrome