下载MP4文件而不是使用ChromeDriver播放吗? [英] Download MP4 file instead of playing it using ChromeDriver?
问题描述
我正在使用Chrome Web驱动程序2.10 chromedriver_win32.zip 与 Selenium WebDriver 2.31.2 .
I'm using Chrome Web Driver 2.10 chromedriver_win32.zip with Selenium WebDriver 2.31.2.
启用了详细日志记录后, DesiredCapabilities ( https://sites.google.com/a/chromium.org/chromedriver/capabilities )通过得很好,
With verbose logging enabled it seems the DesiredCapabilities (https://sites.google.com/a/chromium.org/chromedriver/capabilities) are passed just fine,
[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 ,而不是下载.
but Chrome Web Driver is playing *.mp4 instead of downloading.
我已经在如何尝试该解决方案使用Selenium Webdriver .NET绑定设置Chrome偏好设置?,但是它似乎不适用于更新的Chrome Web Driver版本,如果我尝试使用 chromedriver_win_26.0.1383.0 .
I've tried the solution at How to set Chrome preferences using Selenium Webdriver .NET binding? but it doesn't seem to work with newer Chrome Web Driver version, and it crashes if i try and use selenium-dotnet-2.31.2 with 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);
这篇关于下载MP4文件而不是使用ChromeDriver播放吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!