Capabilities不推荐使用仅与一起构建的旧方法。现在,它以
ChromeDriverService&
Capabilities为参数。因此,只需构建一个,
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);
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)