gpt4 book ai didi

java - ChromeDriver(Capabilities 能力) 已弃用

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:59:21 32 4
gpt4 key购买 nike

我使用 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);

我在文档中找到了这个:

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

最佳答案

我希望您想询问避免弃用的解决方法。

仅使用 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 并仅使用 ChromeOptionssetCapability 方法,例如,

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

关于java - ChromeDriver(Capabilities 能力) 已弃用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46786043/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com