How do I set Chrome download directory with Selenium & VBA

Viewed 8484

Using Win7, Office2010, Chrome 58, and Selenium 2.0.9, I'm automating the downloading of a number of files from a few websites (NB, I actually need the files and the sites are not mine - I'm not testing my own site), and I'd like to control where the files end up being downloaded.

I have looked at quite a number of search results and everything I've found has led me to the following versions of code, each Driver.SetPreference variation has been tested independently and none of them work.

Private Sub DownloadDirTest()

  Dim Driver As Selenium.ChromeDriver
  Set Driver = New Selenium.ChromeDriver

  Driver.SetPreference "browser.download.dir", "\\server\share\my\long\path"
  Driver.SetPreference "browser.download.dir", "\\\\server\\share\\my\\long\path"
  'after mapping Y: to "\\server\share\my\long\path" in Windows Explorer
  Driver.SetPreference "browser.default_directory", "Y:\"
  Driver.SetPreference "browser.download.dir", "c:\"
  Driver.SetPreference "browser.default_directory", "c:\"

  Driver.Start "Chrome", "http://google.com"

  Driver.Close

End Sub

As can been seen here:

enter image description here

Most of the references I've seen are for Python, Java or Ruby, and they all make reference to something like:

ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");

There doesn't seem to be any equivalent ChromeOptions available to VBA.

1) Does anyone know the actual property name to correctly set the download directory?

2) I'm not particularly wedded to Chrome, though it seems to be faster than IEDriver (in my initial testing), and I can't get the current Firefox driver to work. If someone has pointers to how to reliably set the DL directory in either of the other browsers (and a link to an updated Firefox driver - I haven't been able to find it via half-hearted searching), I'm open to using those.

1 Answers
Related