我使用的是Chrome Web Driver 2.10 chromedriver_win32.zip和Selenium WebDriver 2.31.2。
启用详细日志记录后,似乎传递了 DesiredCapabilities (https://sites.google.com/a/chromium.org/chromedriver/capabilities)很好,
[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 Driver正在播放 * .mp4 而不是下载。
我已经在How to set Chrome preferences using Selenium Webdriver .NET binding?上尝试过该解决方案,但它似乎不适用于较新的Chrome Web驱动程序版本,如果我尝试将selenium-dotnet-2.31.2与chromedriver_win_26.0.1383.0一起使用,它会崩溃。
有人有建议吗?
最佳答案
ChromeOptions options = new ChromeOptions();
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_settings.popups", 0);
prefs.put("download.default_directory", getClass().getResource("/data/input").toString().replace("%20", " ").replace("file:","").replaceFirst("/", ""));
options.setExperimentalOption("prefs", prefs);
options.addArguments("--test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
关于google-chrome - 下载MP4文件而不是使用ChromeDriver播放吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23530399/