Chrome参数不起作用 [英] Chrome arguments doesn't work

查看:1155
本文介绍了Chrome参数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道为什么chrome参数不起作用吗?

anybody know why chrome arguments does't work?

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;

public class testowa  {
    public static void main(String[] args) throws InterruptedException {

        DesiredCapabilities capability = DesiredCapabilities.chrome();
        capability.setCapability("chrome.args",
                Arrays.asList("--disable-web-security", "--start-maximized"));
        WebDriver driver = null;
        try {
            URL hub_url = new URL("http://192.168.56.101:4444/wd/hub");
            driver = new RemoteWebDriver(hub_url, capability);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        driver.get("file:///home/test/www/index.html");
    }
}

我之前也试过没有 - 切换器只给出一个参数... Chrome启动,但没有激活标记。

I've tried also without "--" before switchers and giving only one argument... Chrome starts, but without activated flags.

我使用最新的chromedriver。

I use newest chromedriver.

推荐答案

最近发现由于某些原因,功能类无法正常使用当前的Selenium和Chrome(截至Selenium 2.33.0,Chrome 30和2013年7月) 。

I recently discovered that the Capabilities class does not work properly with current Selenium and Chrome for some reason (as of Selenium 2.33.0, Chrome 30 and July 2013).

我相信我联系的答案也是你问题的解决方案。只需使用 ChromeOptions ,这些一直对我有用:

The answer I linked is also, I believe, the solution to your problem. Simply use ChromeOptions, these have been working for me well:

ChromeOptions options = new ChromeOptions();
options.addArgument("--disable-web-security");
options.addArgument("--start-maximized");

// For use with RemoteWebDriver:
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
RemoteWebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capabilities);

这篇关于Chrome参数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆