I want to verify file download using Selenium WebDriver and Java. The file to download is of PDF format. When WebDriver clicks on "Download" link in the AUT, Firefox opens up the following download confirmation window:
I want Firefox to download the file automatically without showing above confirmation window, so I used the below code:
FirefoxProfile firefoxProfile=new FirefoxProfile(); firefoxProfile.setPreference("browser.download.folderList",2); firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false); firefoxProfile.setPreference("browser.download.dir",downloadPath); firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/pdf"); WebDriver driver=new FirefoxDriver(firefoxProfile);
but still Firefox shows the same window. How can I set Firefox profile so that PDF files are downloaded automatically without showing the confirmation dialogue?
Chosen SolutionClick the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "Always ask me where to save files". Click the Firefox button, go to Options | Options | General and in the Downloads menu, checkmark the option "'''Always ask me where to save files'''".
FirefoxOptions options = new FirefoxOptions(); FirefoxProfile profile = new FirefoxProfile();
Just like @Jason suggested, it's most probably another mime type. To get the mime type:
Then to download a PDF with Firefox:
FirefoxOptions options = new FirefoxOptions(); options.setPreference("browser.download.folderList", 2); options.setPreference("browser.download.dir", "C:\\Windows\\temp"); options.setPreference("browser.download.useDownloadDir", true); options.setPreference("browser.download.viewableInternally.enabledTypes", ""); options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/pdf;text/plain;application/text;text/xml;application/xml"); options.setPreference("pdfjs.disabled", true); // disable the built-in PDF viewer WebDriver driver = new FirefoxDriver(options); driver.get("https://www.mozilla.org/en-US/foundation/documents"); driver.findElement(By.linkText("IRS Form 872-C")).click();
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