Possible duplicate: http://stackoverflow.com/questions/25779027/load-default-chrome-profile-with-webdriverjs-selenium
I'm trying to run Selenium automation and due to sophisticated authentication mechanisms (smart card + redirects) I'd like to use existing browser profile (rather than fresh browser instance each time).
I'm using JavaScript driver - https://code.google.com/p/selenium/wiki/WebDriverJs
var webdriver = require('selenium-webdriver');
var chromeOptions = webdriver.Capabilities.chrome();
// !!! HERE !!!
chromeOptions.set("--user-data-dir", "'c:\\Users\\a-miste\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1\\'");
var driver = new webdriver.Builder().withCapabilities(chromeOptions).build();
// Using Facebook / Gmail because it is easier to tell if I'm using a profile that I'm already logged in
driver.get('http://www.gmail.com');
driver.wait(function() {
return driver.getTitle().then(function(title) {
console.log("title: " + title);
return true;
});
}, 5000);
driver.quit();
The question has an answer for C# - http://stackoverflow.com/questions/18034747/unable-to-load-default-profile-in-chrome-with-selenium-webdriver/18037924 - and Java - http://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver - both are using addArguments
syntax.
Looking at the source - https://code.google.com/p/selenium/source/browse/javascript/node/selenium-webdriver/chrome.js#405 - it seems like addArguments
method should be available as well:
In my code I'm using chromeOptions.set
because addArguments
method is not there (undefined is not a function). Using node-inspector I was able to see:
I've also tried using chrome.switches
- https://kowalcj0.wordpress.com/2011/06/15/use-custom-chrome-profile-with-selenium-webdriver/ - and manually setting options as suggested here angular/protractor#175 (comment)
chromeOptions['caps_'].chromeOptions={
args:['--user-data-dir=c:\\Users\\a-miste\\AppData\\Local\\Google\\Chrome\\User Data\\Profile 1\\']
};
Overally a lot of trial and error. I'm pretty sure it can be solved easily but at this stage I just need some help...
https://sites.google.com/a/chromium.org/chromedriver/capabilities
you can use the user-data-dir Chrome command-line switch to tell Chrome which profile to use:
ChromeOptions options = new ChromeOptions();
options.addArguments("user-data-dir=/path/to/your/custom/profile");