I'm trying to specify a file download directory for my Node.js Selenium Chrome driver. Here is my code for creating the web driver:
var downloadFolder = '/Users/andrew/Desktop';
var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.setUserPreferences({'download.default_directory': downloadFolder}))
.build();
My experiment shows my downloaded file still goes to the default /Users/andrew/Download
folder. Am I doing something wrong here? Using selenium-webdriver
as my module by the way.
I'm trying to specify a file download directory for my Node.js Selenium Chrome driver. Here is my code for creating the web driver:
var downloadFolder = '/Users/andrew/Desktop';
var driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.setUserPreferences({'download.default_directory': downloadFolder}))
.build();
My experiment shows my downloaded file still goes to the default /Users/andrew/Download
folder. Am I doing something wrong here? Using selenium-webdriver
as my module by the way.
- Did you end up finding a solution to this? – scottazord Commented Jul 5, 2018 at 5:15
- not yet, I think this might be a bug – toadead Commented Jul 18, 2018 at 22:14
- Actually the code that you shared is working for me, im using chrome v76 and from npm: "chromedriver": "^76.0.0", "selenium-webdriver": "^4.0.0-alpha.4" – Nestor Perez Commented Aug 14, 2019 at 20:10
4 Answers
Reset to default 4for me this work .. or else u can go in /node_modules/selenium-webdriver/chrome.js check the functions.
let chrome = require('selenium-webdriver/chrome');
let { Builder } = require('selenium-webdriver');
var driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options().setUserPreferences(
{ "download.default_directory": task.download_dir }
))
.build();
I also had the same issue with specifying the download directory for Chrome driver using Node.js. Did some research online and found that prefs can be used in Chrome options and that there is a specific way of formatting it. The code below worked for me. Try it out and let me know.
var chrome = require('chromedriver');
var chromeCapabilities = webdriver.Capabilities.chrome();
const chromeOption = require('selenium-webdriver/chrome');
//setting chrome options to start the browser fully maximized
var chromeOptions = {
'args': ['--test-type', '--start-maximized'],
'prefs': {"download.default_directory":"/home/(user)/Downloads/Chrome_test"}
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder()
.withCapabilities(chromeCapabilities)
.build();
I had a similar issue using the chromedriver 2.30, if this is the case for you, try to update it to the (currently) latest 2.33 version
I tried with the below two codes, yet the file is not getting saved to my specified path:
var downloadFolder = 'E:/CannonGroup/DownloadedAPfile';
var driver = new Builder()
.forBrowser('chrome')
.setChromeOptions(new chrome.Options()
.setUserPreferences({'download.default_directory': downloadFolder}))
.build();
var chromeCapabilities = webdriver.Capabilities.chrome();
var chromeOptions = {
'prefs': {"download.default_directory":"C:/Raksha"}
};
chromeCapabilities.set('chromeOptions', chromeOptions);
var driver = new webdriver.Builder()
.withCapabilities(chromeCapabilities)
.build();