Opening Selenium firefox pdf profile profile when pdfjs.disabled is true and Adobe Reader is installed

I am trying to download a pdf file using the Selenium web driver with Java. It was great when I launched it about 2 weeks ago, but now every time he clicks on a link in pdf format, he opens a PDF reader.

My firefox profile that I create in the test was not changed, it set the download location and automatically downloads the file if it is pdf or csv. The csv files still work correctly and load in the correct folder.

In my code, I have set pdfjs.disabled to true, and if I open about about: config in a firefox instance for webdriver, I see that this is true.

If I set pdfjs.disabled to true in another instance of firefox and manually click the link in which it works correctly.

I am not sure if firefox has been updated since the last test run, but I also installed adobe reader on my computer.

Please tell me what could have caused it to suddenly stop working?

This is the profile that I create and the way I call 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 uninstalled Adobe Reader and it started working again. Reader must install something in the profile that I need to disable in order to make it work with the reader. Does anyone have any ideas?

+4
source share
1 answer

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 PDF MIME to the plugin.disable_full_page_plugin_for_types parameter.

This worked for Firefox 26.

+1
source

Source: https://habr.com/ru/post/1481624/


All Articles