I am trying to download a pdf file using Selenium web driver with Java. This was working fine the last time I run it about 2 weeks ago, but now every time it clicks on the pdf link it is opening the pdf reader.
My firefox profile I create in the test hasn't been changed, it set a download location and sets file to download automatically if they're pdf or csv. The csv files are still working correctly and download to the correct folder.
In my code I have pdfjs.disabled set to true and if I open the about:config in the webdriver firefox instance I can see this is set correctly.
If I set pdfjs.disabled to true in another firefox instance and manually click a link it works correctly.
I'm not sure if firefox has been updated since I last run the test but I have also installed adobe reader on my computer.
Please can anyone tell me what could have made it suddenly stop working?
This is the the profile I create and the way I call the webdriver. I am using Firefox 21.0 which is the latest version.
FirefoxProfile firefoxProfile = new FirefoxProfile();
// Set profile to accept untrusted certificates
firefoxProfile.setAcceptUntrustedCertificates(true);
//Set profile to not assumet certificate issuer is untrusted
firefoxProfile.setAssumeUntrustedCertificateIssuer(false);
//Set download location and file types
firefoxProfile.setPreference("browser.download.folderList",2);
firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
firefoxProfile.setPreference("browser.download.dir",reportFolder);
firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","text/csv,application/pdf,application/csv,application/vnd.ms-excel");
// Set to false so popup not displayed when download finished.
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
firefoxProfile.setPreference("browser.download.manager.showAlertOnComplete",false);
firefoxProfile.setPreference("browser.download.manager.showWhenStartinge",false);
firefoxProfile.setPreference("browser.download.panel.shown",false);
firefoxProfile.setPreference("browser.download.useToolkitUI",true);
// Set this to true to disable the pdf opening
firefoxProfile.setPreference("pdfjs.disabled", true);
driver = new FirefoxDriver(firefoxProfile);
UPDATE: I removed adobe reader and this started working again. Reader must set something in the profile that I need to disable to get it working with reader. Does anybody have any ideas?
Try
firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");
The trick is to add the PDF MIME to the plugin.disable_full_page_plugin_for_types preference.
This worked for Firefox 26.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With