Andrew Heckman
Andrew Heckman

Reputation: 31

Problem setting default download directory in Watir after update

We recently updated our Watir version from 6.8 to 6.19 in anticipation of the 7.0 beta. Since then, our browser configuration that sets the default directory for chrome has stopped working. Our method that sets it is below.

    def setup

      prefs = {
        download: {
          prompt_for_download: false,
          default_directory: @download_dir
        }
      }

      Watir::Browser.new :chrome, options: { prefs: prefs }
    end

@download_dir is set as the dir that I want and I have confirmed that by checking the value with a breakpoint after prefs has been defined.

As far as I can tell, this is how http://watir.com/guides/chrome/ specifies that you should set this up. This method worked fine before the update. I've tried some of the solutions from similar issues on SO with no success.

I receive no errors as far as I can tell, and our testing suite runs fine other than downloading to the chrome default folder instead.

Thanks in advance!

Upvotes: 1

Views: 355

Answers (2)

goodniceweb
goodniceweb

Reputation: 166

I've tried using "prompt_for_download" as a string as well as all other inputs but that did not work.

Changing a driver directly worked for me though:

browser = Watir::Browser.new(:chrome, options: { prefs: prefs })
browser.driver.download_path = downloads_path

where downloads_path represents the custom directory you want to set.

Upvotes: 0

Andrew Heckman
Andrew Heckman

Reputation: 31

As mentioned in the comments, this is due to a bug in selenium detailed here github.com/SeleniumHQ/selenium/issues/7917.

Using strings in the style of "prompt_for_download" => false fixes the problem.

Upvotes: 2

Related Questions