Skip to content

Instantly share code, notes, and snippets.

@stefek99
Created July 31, 2015 09:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stefek99/87533df1b35ac5df0d85 to your computer and use it in GitHub Desktop.
Save stefek99/87533df1b35ac5df0d85 to your computer and use it in GitHub Desktop.
This is an unasked question I was about to create on StackOverflow

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: enter image description here

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:

enter image description here


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


DOCS

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");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment