How to address “The constructor ChromeDriver(Capabilities) is deprecated” and WebDriverException: Timed out error with ChromeDriver and Chrome

后端 未结 1 794
隐瞒了意图╮
隐瞒了意图╮ 2021-01-24 09:32

I\'m trying to config the default download directory as below, it\'s works correctly but I\'m having two issues :

    String exePath = \"src\\\\Drivers\\\\chrom         


        
相关标签:
1条回答
  • 2021-01-24 10:16

    It seems you were almost there. You need to use the method merge() from MutableCapabilities Class to merge the DesiredCapabilities type of object into ChromeOptions type object and initiate the WebDriver and WebClient instance by passing the ChromeOptions object as follows :

    String exePath = "src\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    String downloadFilepath = "U:\\Data\\Download";
    HashMap<String, Object> chromePrefs = new HashMap<String, Object>();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadFilepath);
    ChromeOptions options = new ChromeOptions();
    options.setExperimentalOption("prefs", chromePrefs);
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    options.merge(cap);
    driver = new ChromeDriver(options);
    
    0 讨论(0)
提交回复
热议问题