Unable to download pdf in firefox | Selenium Forum
M
Posted on 04/08/2016
Hi,

i am using the following code for verifying text in pdf. Its working for chrome, but for firefox i get the option weather to open or save the pdf file.

String path=getDownFilePath(filename,pdf);
frFile = new File(path);

try
{
PDFParser parser = new PDFParser((RandomAccessRead) new RandomAccessFile(frFile,"r"));
parser.parse();

cosDoc = parser.getDocument();
pdfStripper = new PDFTextStripper();

String output=new PDFTextStripper().getText(parser.getPDDocument());
Assert.assertTrue(output.contains(verifyText), "Verified");
logger.info("Verified, PDF file ' "+output+ " ' contains ' "+verifyText+" '");
parser.getPDDocument().close();
}

i am using the following mime types

profile.setEnableNativeEvents(true);
profile.setPreference("browser.download.folderList", 2);
profile.setPreference("browser.download.manager.showWhenStarting", false);
profile.setPreference("browser.download.dir",CommonConstants.FILEDOWNLOADPATH);
profile.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf,application/force-download,application/x-download,text/csv,text/plain,image/jpeg,application/vnd.ms-excel,application/zip");
profile.setPreference("pdfjs.disabled", true);
capability = DesiredCapabilities.firefox();
capability.setCapability("unexpectedAlertBehaviour", "ignore");
capability.setCapability(FirefoxDriver.PROFILE, profile);
driver = new FirefoxDriver(capability);

Kindly advice

M
Replied on 05/08/2016

you can try

profile["pdfjs.disabled"] =false


but best way wouldbe to download the pdf file and then read the file through PDFBox.


M
Replied on 08/08/2016

Sorry it didnt work.. Kindly advice


M
Replied on 08/08/2016

you want to download PDF file, right?


M
Replied on 08/08/2016

yes , i want to


M
Replied on 08/08/2016

take a look at this q/a

http://stackoverflow.com/questions/13429942/downloading-a-pdf-file