Setting Firefox download.dir with watir-webdriver on Windows

I was recently unsuccessfully trying to set the Firefox download directory on Windows using a Watir-WebDriver/Selenium-WebDriver profile. Thanks to a comment on this blog, it turns out there is a bug whereby if your download path contains a \n or \r, then it reverts back to the default location.

So, a download path like “C:\new\raw” will fail without telling you why.

Fortunately, it’s now been fixed, but hasn’t been released, so in the meantime, you can double escape it

require 'watir-webdriver'
p =
p[''] = "C:\\\\new\\\\raw"
p[''] = 2
p['browser.helperApps.neverAsk.saveToDisk'] = "application/pdf"
b = :firefox, :profile => p

Author: Alister Scott

Alister is an Excellence Wrangler for Automattic.