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!!

2
  • Here is an answer for Java but it might work here as well: stackoverflow.com/questions/34515328/… Commented Aug 22, 2019 at 17:45
  • @AndiCover setExperimentalOption doesn't exists on NodeJS chrome options :-/ Commented Aug 22, 2019 at 19:09

1 Answer 1

7

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!

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mate. You saved my life. I spend half a day trying to figure it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.