1

I have a Node.js file that looks like this:

var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');

var driver = new webdriver.Builder()
  .withCapabilities(webdriver.Capabilities.chrome())
  .setChromeOptions(new chrome.Options().setUserPreferences(
    { "download.default_directory": dir.join(__dirname, 'extensions')}
  ))
  .build();

driver.get("[URL to Download]")

When I run this, it downloads the item I want, but chrome warns that the file might not be safe: enter image description here

Is there Any way to automatically accept the download or click continue?

Luke Vanzweden
  • 466
  • 3
  • 15
  • Is the objective to just download files locally? There are other ways to do this without chrome. – Nick.Mc Feb 26 '21 at 02:57
  • @Nick.McDermaid yes, when I navegate to the url, it downloads it, is there a better way to do this? – Luke Vanzweden Feb 26 '21 at 03:00
  • 1
    I googled and found this. https://stackoverflow.com/questions/11944932/how-to-download-a-file-with-node-js-without-using-third-party-libraries – Nick.Mc Feb 26 '21 at 04:45

1 Answers1

2

There is a download.prompt_for_download preference available for Chrome. Try adding it

var driver = new webdriver.Builder()
  .withCapabilities(webdriver.Capabilities.chrome())
  .setChromeOptions(new chrome.Options().setUserPreferences(
    { "download.default_directory": dir.join(__dirname, 'extensions'),
      "download.prompt_for_download": false
    }
  ))
  .build();
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77