3

After I download a file using Selenium and Chrome driver, how do I get the name of the file?

This site avoids the question but gives examples for simple cases: http://ardesco.lazerycode.com/index.php/2012/07/how-to-download-files-with-selenium-and-why-you-shouldnt/

My link is a JavaScript link that pops up a new window and automatically downloads the file, and the file name is dynamically generated on the server.

This site suggests changing the download location, but for Firefox: http://elementalselenium.com/tips/2-download-a-file

This lists all the command line options but there are none for setting the download filter: http://www.ericdlarson.com/misc/chrome_command_line_flags.html

This question suggests that you can change the directory, but the answer is in Java and it doesn't work for PHP: Chrome Web Driver download files

I tried the following, but it gave an error:

 $options = new ChromeOptions(); $options->setExperimentalOption('download.default_directory', '\\temp'); $capabilities = DesiredCapabilities::chrome(); // htmlUnitJS() $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); $driver = RemoteWebDriver::create($host, $capabilities, 5000); 

PHP Fatal error: Uncaught exception 'UnknownServerException' with message 'unknown error: cannot parse capability: chromeOptions from unknown error: unrecognized chrome option: download.default_directory

Possibly relevant: https://groups.google.com/forum/#!topic/macenterprise/cmSKIyzjQA8https://github.com/facebook/php-webdriver/wiki/ChromeOptions

    1 Answer 1

    2

    I changed it to this and it worked. It did not like the \temp path, and it wanted an associative array.

     $options = new ChromeOptions(); $prefs = array('download.default_directory' => 'c:/temp/'); $options->setExperimentalOption('prefs', $prefs); $capabilities = DesiredCapabilities::chrome(); // htmlUnitJS() $capabilities->setCapability(ChromeOptions::CAPABILITY, $options); $driver = RemoteWebDriver::create($host, $capabilities, 5000); 

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.