1

I'm trying to use node selenium in Firefox to click a link in the browser, which then triggers a download of an excel file to take place. I'd like the file to download to a set directory, but when the link is clicked, a dialog box appears asking if I'd like to save the file or open it. I've tried setting options both in the code and within the Firefox browser itself, but have had no luck. Here is the code I am currently using...

let options = new firefox.Options();

options.setPreference("browser.download.dir", "C:\\recapp_excel");
options.setPreference("browser.helperApps.alwaysAsk.force", false);

let driver = await new Builder()
  .forBrowser('firefox')
  .setFirefoxOptions(options)
  .build();
  • Possible duplicate of [Automatic download file from web page](https://stackoverflow.com/questions/33684136/automatic-download-file-from-web-page) – jay.sf Jun 18 '18 at 17:33

1 Answers1

0

try this code :

let options = new firefox.Options();
options.setPreference("browser.download.folderList", 2);
options.setPreference("browser.download.dir", "C:\\recapp_excel");
options.setPreference("browser.download.useDownloadDir", true);
options.setPreference("browser.helperApps.neverAsk.saveToDisk", "application/vnd.ms-excel");  
options.setPreference("pdfjs.disabled", true);  // disable the built-in PDF viewer

Reference :

Downloading excel file using selenium

cruisepandey
  • 28,520
  • 6
  • 20
  • 38
  • I am still experiencing the same issue when using this code. The dialog box still appears, and the file is never downloaded to my drive. – Michael Kitchell Jun 18 '18 at 15:26
  • follow these steps : – cruisepandey Jun 18 '18 at 15:27
  • 1. Open Developer Tools and then the Network tab 2. Go back to the page and click on the file to download 3.Go back to the network panel and select the first request 4.Copy the mime type on the right of Content-Type from the response header: 5.Set the preference "browser.helperApps.neverAsk.saveToDisk" with your mime type 6.Make sure the download folder "browser.download.dir" exists – cruisepandey Jun 18 '18 at 15:28
  • you can use robot class or auto it script to handle prompt. – cruisepandey Jun 18 '18 at 15:33