Define download directory for chromedriver selenium with python

前端 未结 3 2006
[愿得一人]
[愿得一人] 2021-02-04 15:54

Everything is in the title!

Is there a way to define the download directory for selenium-chromedriver used with python?

In spite of many research, I haven\'t fou

3条回答
  •  迷失自我
    2021-02-04 16:21

    Please try the below code....

    System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");
    String downloadFilepath = "/path/to/download";
    HashMap chromePrefs = new HashMap();
    chromePrefs.put("profile.default_content_settings.popups", 0);
    chromePrefs.put("download.default_directory", downloadFilepath);
    ChromeOptions options = new ChromeOptions();
    HashMap chromeOptionsMap = new HashMap();
    options.setExperimentalOptions("prefs", chromePrefs);
    options.addArguments("--test-type");
    DesiredCapabilities cap = DesiredCapabilities.chrome();
    cap.setCapability(ChromeOptions.CAPABILITY, chromeOptionsMap);
    cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    WebDriver driver = new ChromeDriver(cap);
    

提交回复
热议问题