ChromeDriver(功能功能)已弃用 [英] ChromeDriver(Capabilities capabilities) is deprecated

查看:2563
本文介绍了ChromeDriver(功能功能)已弃用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 ChromeDriver 2.33 WebDriver 3.6.0 并尝试设置文件下载的默认目录。

I use ChromeDriver 2.33 with WebDriver 3.6.0 and try to set default directory for file download.

Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("download.default_directory", Vars.DOWNLOAD_FOLDER_ROOT);
DesiredCapabilities caps = DesiredCapabilities.chrome();

ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.setExperimentalOption("prefs", prefs);
caps.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(caps);

我在docs中找到了这个:

I found this in docs:


请改用ChromeDriver(ChromeOptions)。创建一个新的ChromeDriver
实例。这些功能将被传递给chromedriver服务。

Use ChromeDriver(ChromeOptions) instead. Creates a new ChromeDriver instance. The capabilities will be passed to the chromedriver service.


推荐答案

我希望你想问一下避免弃用的解决方法。

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

不推荐使用功能构建的旧方法。现在,需要 ChromeDriverService & 功能作为参数。因此,只需构建一个 ChromeDriverService ,并将其与功能一起传递,以删除弃用警告。

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);

编辑:
ChromeDriver (服务,功能)现在也被弃用,你可以使用,

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);

但是,您可以完全跳过 DesiredCapabilities 和仅使用 ChromeOptions setCapability 等方法,

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);

这篇关于ChromeDriver(功能功能)已弃用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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