ChromeDriver(Capabilities capabilities) is deprecated

纵然是瞬间 提交于 2019-11-29 00:11:38

I hope you wanted to ask about the workaround to avoid the deprecation.

The old method of just building with Capabilities is deprecated. Now, it takes a ChromeDriverService & Capabilities as parameters. So, just a build a ChromeDriverService and pass the same along with your Capabilities to remove the deprecation warning.

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

ChromeDriverService service = new ChromeDriverService.Builder()
                    .usingDriverExecutable(new File("/usr/local/chromedriver"))
                    .usingAnyFreePort()
                    .build();
ChromeDriver driver = new ChromeDriver(service, capabilities);

EDIT: Since ChromeDriver(service, capabilities) is deprecated now as well, you can use,

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

ChromeDriverService service = new ChromeDriverService.Builder()
                            .usingDriverExecutable(new File("/usr/local/chromedriver"))
                            .usingAnyFreePort()
                            .build();
ChromeOptions options = new ChromeOptions();
options.merge(capabilities);    
ChromeDriver driver = new ChromeDriver(service, options);

However, You can completely skip DesiredCapabilities and use only ChromeOptions with setCapability method like,

ChromeOptions options = new ChromeOptions();
options.setCapability("capability_name", "capability_value");
driver = new ChromeDriver(options);

The new way to use chrome capabilities is like this :

ChromeOptions options = new ChromeOptions();
    // Proxy proxy = new Proxy();
    // proxy.setHttpProxy("myhttpproxy:3337");
    // options.setCapability("proxy", proxy);
    // options.addArguments("--headless");
    // options.addArguments("--disable-gpu");
    // options.setAcceptInsecureCerts(true);
    // options.addArguments("--allow-insecure-localhost");
    // options.addArguments("--lang=fr-CA");
    options.addArguments("--start-maximized");
driver = new ChromeDriver(options);

You can get more options by looking at this site : https://sites.google.com/a/chromium.org/chromedriver/capabilities

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!