Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.2k views
in Technique[技术] by (71.8m points)

google chrome - Download MP4 file instead of playing it using ChromeDriver?

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 (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": ""

}

but Chrome Web Driver is playing *.mp4 instead of downloading.

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.

Anybody has a suggestion?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
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);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...