ChromeDriver(功能功能)已弃用

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

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

我在文档中找到了这个:

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

回答:

我希望您想问一下解决方法,以避免过时。

Capabilities不推荐使用仅与一起构建的旧方法。现在,它以ChromeDriverServiceCapabilities为参数。因此,只需构建一个,ChromeDriverService然后将其与您一起传递Capabilities即可删除弃用警告。

DesiredCapabilities capabilities = DesiredCapabilities.chrome();

ChromeDriverService service = new ChromeDriverService.Builder()

.usingDriverExecutable(new File("/usr/local/chromedriver"))

.usingAnyFreePort()

.build();

ChromeDriver driver = new ChromeDriver(service, capabilities);

由于ChromeDriver(service, capabilities)现在也已弃用,因此您可以使用,

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方法一起使用,

ChromeOptions options = new ChromeOptions();

options.setCapability("capability_name", "capability_value");

driver = new ChromeDriver(options);

以上是 ChromeDriver(功能功能)已弃用 的全部内容, 来源链接: utcz.com/qa/429717.html

回到顶部