1

I'm trying to set download location for Chrome browser but I'm stuck.

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

const chromeOptions = new chrome.Options();
chromeOptions.set('download.default_directory', __dirname + '/download');

const builder = await new Builder()
    .forBrowser('chrome')
    .setChromeOptions(chromeOptions)
    .build();

What am I doing wrong or what is the correct method to pass my own download folder?

Many thanks!!

Michael Czolko
  • 2,698
  • 2
  • 15
  • 25
  • Here is an answer for Java but it might work here as well: https://stackoverflow.com/questions/34515328/how-to-set-default-download-directory-in-selenium-chrome-capabilities – AndiCover Aug 22 '19 at 17:45
  • @AndiCover setExperimentalOption doesn't exists on NodeJS chrome options :-/ – Michael Czolko Aug 22 '19 at 19:09

1 Answers1

6

I've finally find out.

const { Builder } = require('selenium-webdriver')
const chrome = require('selenium-webdriver/chrome')

const chromePrefs = { 'download.default_directory': __dirname + '/download' }
const chromeOptions = new chrome.Options().setUserPreferences(chromePrefs)

const driver = await new Builder()
  .forBrowser('chrome')
  .setChromeOptions(chromeOptions)
  .build()
  .catch(e => console.error(e))

in NodeJS setUserPreferences are nolonger experimental!

Michael Czolko
  • 2,698
  • 2
  • 15
  • 25