Automation · Blogroll · firefox · QA · selenium · Selenium-webdriver · watir-webdriver

Watir / Selenium Web Driver – Browser Downloads — Solution to download pdf files automatically in firefox 20+ version


Solution to download pdf files automatically in firefox 20+ version using Selenium webdriver or Watir webdriver



I have tried to save PDF files automatically using the below link —  and I have followed the same as per the mentioned page and reference website. But still the firefox browser not downloaded PDF files automatically.


In Firefox latest versions, They have added new function called as ‘Portable Document Format’ which causes the issue


Please try the below code for latest firefox versions.

download_directory = "#{Dir.pwd}/downloads"

download_directory.gsub!("/", "\\") if
profile =
profile[''] = 2 # custom location
profile[''] = download_directory
profile['browser.helperApps.neverAsk.saveToDisk'] = "text/csv,application/pdf"

profile[‘pdfjs.disabled’] = true
profile[‘pdfjs.firstRun’] = false

b = :firefox, :profile => profile
profile[‘pdfjs.disabled’] = true
profile[‘pdfjs.firstRun’] = false
These 2 lines are added. Thats it 🙂

11 thoughts on “Watir / Selenium Web Driver – Browser Downloads — Solution to download pdf files automatically in firefox 20+ version

  1. Hi,
    I have a link.when I clicked the link it will open new dialog box. I want to click save button on dialog box or it will auto save.
    Could you please let me know How to implement it in my code.

    my code is :

    require ‘selenium-webdriver’
    browser = Selenium::WebDriver.for :firefox
    browser.get “http://xxxx/yyyyy”

    this will open new dialog box. where i need to implement ur code .

    Thanks in advance…

    1. Suresh,

      The dialog is different for FF and Chrome. Thats why we are creating profile with Auto download option,

      browser = Selenium::WebDriver.for :firefox

      Instead of this try the above code

      Sorry for the delayed reply.

        1. Alex, Oh!! If the above script is not working for you then we need to find the alternate way to complete this. If any help required pls call me on +91 9941414834. Sorry for the post and inconvenience.

  2. Hi,
    i want to download a pdf file and have writtten the bellow code . But its not working. Pls help
    public class BookDownload {

    public static void main(String[] args)
    FirefoxProfile profile=new FirefoxProfile();
    profile.setPreference(“plugin.disable_full_page_plugin_for_types”, “application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml”);
    WebDriver driver=new FirefoxDriver(profile);
    WebDriverWait wait=new WebDriverWait(driver,20);
    wait.until(ExpectedConditions.elementToBeClickable(By.linkText(“Instant Selenium Testing Tools Starter”)));
    driver.findElement(By.linkText(“Instant Selenium Testing Tools Starter”)).click();



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s