ChromeDriver(Capabilities capabilities) is deprecated

后端 未结 2 463
鱼传尺愫
鱼传尺愫 2020-12-03 06:26

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

Map prefs =          


        
2条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 06:36

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

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

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

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

提交回复
热议问题