簡體   English   中英

當pdfjs.disabled為true並且安裝了adobe reader時,Selenium firefox配置文件打開pdf

[英]Selenium firefox profile opening pdf read when pdfjs.disabled is true & adobe reader is installed

我正在嘗試使用帶有Java的Selenium Web驅動程序下載pdf文件。 我上次約兩周前運行它時工作正常,但現在每次點擊pdf鏈接時都會打開pdf閱讀器。

我在測試中創建的我的firefox配置文件沒有被更改,它設置了一個下載位置並設置文件,如果它們是pdf或csv則自動下載。 csv文件仍然可以正常工作並下載到正確的文件夾。

在我的代碼中,我將pdfjs.disabled設置為true,如果我在webdriver firefox實例中打開about:config,我可以看到這是正確設置的。

如果我在另一個firefox實例中將pdfjs.disabled設置為true並手動單擊鏈接,則它可以正常工作。

自從我上次運行測試以來我不確定firefox是否已更新,但我還在我的計算機上安裝了adobe reader。

請任何人都可以告訴我它可能會突然停止工作?

這是我創建的配置文件以及我調用webdriver的方式。 我使用的是最新版本的Firefox 21.0。

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);

更新:我刪除了adobe reader,這又開始了。 讀者必須在配置文件中設置我需要禁用的內容才能使其與讀者一起工作。 有人有什么想法嗎?

嘗試

firefoxProfile.setPreference("plugin.disable_full_page_plugin_for_types", "application/pdf,application/vnd.adobe.xfdf,application/vnd.fdf,application/vnd.adobe.xdp+xml");

訣竅是將PDF MIME添加到plugin.disable_full_page_plugin_for_types首選項。

這適用於Firefox 26。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM