5

I am new to Selenium and Webdriver. I am trying to write tests using Webdriverjs in node. I want selenium to load my default chrome profile. This is what I am trying, but it still loads a new chrome profile.

var webdriver = require('selenium-webdriver');
var chrome = require('selenium-webdriver/chrome');
var o = new chrome.Options();
o.addArguments("--user-data-dir=/Users/karnesh/Library/Application Support/Google/Chrome/Default");
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome())
            .setChromeOptions(o).build(); 

Any ideas where I am going wrong??

Also, I was not able to find a documentation for webdriverjs. Any links to it (if it exists) would be helpful . Thanks

7
  • If I use your code here, it works: the instance started by Selenium uses the directory specified by --user-data-dir. Make sure you've got the right path. I installed Selenium 2.46.1. Commented Jul 30, 2015 at 13:58
  • @Louis: how do you verify that it uses the right profile? I replaced path with "--user-data-dir=c:\\Users\\a-miste\\AppData\\Local\\Google\\Chrome\\User Data\\Default\\" (I'm on Windows8) and it still loads the new one... Commented Jul 30, 2015 at 14:04
  • @MichalStefanow I created a fresh profile because I did not want it to use my regular profile. Then I modified this profile by adding a single extension. Then I ran the script. Chrome came up with the extension that I had added to this profile so I know it did not create a brand new profile for the run. I also tried with a space in the profile path and it still worked. (I thought there could have been a bug that makes Selenium incorrectly pass arguments if there is a space in the middle of a path.) Commented Jul 30, 2015 at 14:09
  • @Louis - thank you for taking your time for clarify. BTW - how do you run Selenium? I'm using node scriptname.js and then using node-inspector I can see what are the values during execution: i.imgur.com/xcBn6wM.png - but still - new profile gets created everytime... (weird) Commented Jul 30, 2015 at 14:18
  • @MichalStefanow Yep, node test.js. I'm on Linux though and you guys are on Windows. At any rate, this question here is a duplicate of that one. The answers there do not use the leading --. Commented Jul 30, 2015 at 14:23

1 Answer 1

10

chrome://version is your friend - by using it you can see what is your current profile path.

I'm using 2.46.1 on Windows8 machine and after wasting (investing) a few hours of my time I realised that Default is appended by default.

enter image description here

So in order to use my another profile - "Profile 1" - I have to copy it somewhere and place it under Default directory.

Not sure if that's a bug or a feature.

UPDATE: https://github.com/SeleniumHQ/selenium/issues/854

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

2 Comments

To select a different profile, say Profile 1, use options.addArguments("profile-directory=Profile 1");
I have copied the profile to another location and tried the same but it is not working still and appending the default in the profile path. Any input? I am using macOS. This is my path of chrome profileoptions.addArguments("user-data-dir=/Users/henry/Documents/POC/Profile 4");

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.