当通过selenium网格运行时,我需要chrome才能最大化。
这是我现在如何初始化它:
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确实出现了,但没有最大化。在通常的ChromeDriver中,我这样做了
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
但我不知道如何将它传递给RemoteWebDriver。有人可以帮忙吗?
答案 0 :(得分:29)
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);
我就是这样做的。
答案 1 :(得分:3)
好的,我找到了,所以让我们回答我自己的问题:)
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);
应该有效:}
答案 2 :(得分:1)
以上解决方案对我不起作用,但确实如此
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);
希望这有助于某人。