我希望你想问一下解决方法,以避免弃用.
不推荐使用Capabilities构建的旧方法.现在,它需要一个ChromeDriverService&能力作为参数.因此,只需构建一个ChromeDriverService并将其与您的功能一起传递,以删除弃用警告.
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeDriverService service = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("/usr/local/chromedriver"))
.usingAnyFreePort()
.build();
ChromeDriver driver = new ChromeDriver(service, capabilities);
编辑:
由于ChromeDriver(服务,功能)现已弃用,您可以使用,
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并仅使用带有setCapability方法的ChromeOptions,例如,
ChromeOptions options = new ChromeOptions();
options.setCapability("capability_name", "capability_value");
driver = new ChromeDriver(options);