RemoteWebDriver Chrome - start maximized
Asked Answered
A

3

11

I need chrome to start maximized when running via the selenium grid.

This is how do I initialize it now:

Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

Chrome does come up, but not maximized. In usual ChromeDriver I did it like this

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

But I dont know how to pass it to RemoteWebDriver. Can anybody help?

Alwitt answered 30/3, 2012 at 11:28 Comment(0)
G
32
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

That's how I do it.

Greatcoat answered 30/3, 2012 at 11:38 Comment(3)
The code above looks good, but when I tried it, I got "cannot parse capability: chromeOptions on the node." Is there something I am missing?Is
Honestly, I don't know, sorry. I didn't observe the Webdriver development over the past two years too much. Try looking for a mention of this in the chsngelog, or post a new question.Ravelin
I found out the answer to my question here code.google.com/p/selenium/issues/detail?id=7043 with new selenium update options is used slightly different.Is
A
3

Ok, I found it, so lets answer my own question :)

Selenium selenium = new DefaultSelenium("localhost", 4444, "*googlechrome", "http://www.google.com");
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

should work :}

Alwitt answered 30/3, 2012 at 11:37 Comment(1)
I will accept your answer - to give you appreciation for the effort. Anyways "google before post" should be new "think before speak" - at least in my case ;)Alwitt
A
1

The above solutions did not work for me but this did

ChromeOptions options = new ChromeOptions();
options.AddArguments("--start-maximized");

DesiredCapabilities capabilities = options.ToCapabilities() as DesiredCapabilities;
capabilities?.SetCapability(CapabilityType.BrowserName, "chrome");

Driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capabilities);

Hope this helps someone.

Anglophile answered 13/12, 2017 at 16:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.