Reputation: 243
I am working on one application. In that application when we click on one button. A PDF file will be opened in a new pop up browser.
Now My requirement is to once I click on the button, instead of opening a new browser. We need to download the file into the framework folder.
"src/main/java/resources" folder.
I need a selenium code in java to support this.
I am using Chrome browser.
Upvotes: 0
Views: 372
Reputation: 2760
Use this :
//Create FireFox Profile object
FirefoxProfile profile = new FirefoxProfile();
//Set Location to store files after downloading.
profile.setPreference("browser.download.dir", "src/main/java/resources");
profile.setPreference("browser.download.folderList", 2);
//Set Preference to not show file download confirmation dialogue using MIME types Of different file extension types.
profile.setPreference("browser.helperApps.neverAsk.saveToDisk",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;");
profile.setPreference( "browser.download.manager.showWhenStarting", false );
profile.setPreference( "pdfjs.disabled", true );
//Pass FProfile parameter In webdriver to use preferences to download file.
FirefoxDriver driver = new FirefoxDriver(profile);
If the above solution doesn't work then use following option :
Upvotes: 1