Google chrome 下载MP4文件而不是使用ChromeDriver播放?
我正在使用Chrome Web驱动程序2.10 启用详细日志记录后,似乎可以很好地传递所需的功能Google chrome 下载MP4文件而不是使用ChromeDriver播放?,google-chrome,selenium,selenium-webdriver,chrome-web-driver,Google Chrome,Selenium,Selenium Webdriver,Chrome Web Driver,我正在使用Chrome Web驱动程序2.10 启用详细日志记录后,似乎可以很好地传递所需的功能 [1.174][FINE]: Initializing session with capabilities { "browserName": "chrome", "chrome.switches": [ ], "chromeOptions": { "args": [ ], "binary": "", "extension
[1.174][FINE]: Initializing session with capabilities {
"browserName": "chrome",
"chrome.switches": [ ],
"chromeOptions": {
"args": [ ],
"binary": "",
"extensions": [ ],
"prefs": {
"download.default_directory": "C:\\Downloads",
"download.directory_upgrade": "true",
"download.extensions_to_open": "",
"download.prompt_for_download": "false"
}
},
"javascriptEnabled": true,
"platform": "WINDOWS",
"version": ""
}
但是Chrome Web驱动程序正在播放*.mp4而不是下载
我曾在尝试过该解决方案,但它似乎不适用于较新的Chrome Web驱动程序版本,如果我尝试使用它,它会崩溃
有人有什么建议吗?我通过以下代码实现了这一点:
System.setProperty(“webdriver.chrome.driver”,“/path/to/chromedriver”);
字符串downloadFilepath=“/path/to/download”;
HashMap chromePrefs=新HashMap();
chromePrefs.put(“profile.default\u content\u settings.popups”,0);
chromePrefs.put(“download.default\u目录”,downloadFilepath);
ChromeOptions选项=新的ChromeOptions();
HashMap chromeOptionsMap=新HashMap();
选项。设置实验选项(“prefs”,chromePrefs);
options.addArguments(“--test type”);
DesiredCapabilities=DesiredCapabilities.chrome();
cap.setCapability(ChromeOptions.CAPABILITY,ChromeOptions sMap);
cap.setCapability(CapabilityType.ACCEPT_SSL_CERTS,true);
上限设置能力(色度选项、能力、选项);
WebDriver=新的ChromeDriver(cap);
ChromeOptions选项=新的ChromeOptions();
Map prefs=新的HashMap();
prefs.put(“profile.default\u content\u settings.popups”,0);
prefs.put(“download.default_目录”,getClass().getResource(“/data/input”).toString().replace(“%20”,”).replace(“文件:”,”).replaceFirst(“/”,”);
选项。设置实验选项(“prefs”,prefs);
options.addArguments(“--test type”);
能力。设置能力(ChromeOptions.CAPABILITY,选项);
这对我来说非常有效:
DesiredCapabilities cap = DesiredCapabilities.firefox();
FirefoxProfile fprofile= new FirefoxProfile();
fprofile.setPreference("browser.download.folderList",2); //0-desktop,1-file download folder,2-specified location
fprofile.setPreference("browser.download.manager.showWhenStarting", false); //prevent download file window
fprofile.setPreference("browser.download.dir","E:\\Downloadfilebyprogram");
fprofile.setPreference("browser.download.manager.focusWhenStarting", false);
//fprofile.setPreference("browser.helperApps.alwaysAsk.force", false);
//fprofile.setPreference("browser.download.manager.closeWhenDone", true);
//fprofile.setPreference("browser.download.manager.useWindow", false);
//fprofile.setPreference("services.sync.prefs.sync.browser.download.manager.showWhenStarting", false);
//fprofile.setPreference("browser.helperApps.neverAsk.openFile,","application/vnd.ms-excel");
fprofile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.ms-excel");
fprofile.setPreference("browser.download.manager.alertOnExeOpen", false); //prevent from opening a file
cap.setCapability(FirefoxDriver.PROFILE, fprofile);
WebDriver driver=new FirefoxDriver(cap);
“getClass().getResource(“/data/input”).toString().replace(“%20”,”).replace(“文件:”,“).replaceFirst(“/”,”)是指向maven目标/data/Inputry的路径,以确保下载目录存在。我犯了一个错误,目录不存在,Chrome会弹出一个对话框询问保存位置。问题是Chrome,而不是Firefox。