Download MP4 file instead of playing it using ChromeDriver?

后端 未结 3 1920
半阙折子戏
半阙折子戏 2020-12-16 02:33

I\'m using Chrome Web Driver 2.10 chromedriver_win32.zip with Selenium WebDriver 2.31.2.

With verbose logging enabled it seems the DesiredCapabilities

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-16 03:06

    I got this working by 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);
    

提交回复
热议问题