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

karyboy
  • 317
  • 1
  • 5
  • 22
  • 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. – Louis Jul 30 '15 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... – Mars Robertson Jul 30 '15 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.) – Louis Jul 30 '15 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: http://i.imgur.com/xcBn6wM.png - but still - new profile gets created everytime... (weird) – Mars Robertson Jul 30 '15 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](http://stackoverflow.com/questions/14480717/load-chrome-profile-using-selenium-webdriver). The answers there do not use the leading `--`. – Louis Jul 30 '15 at 14:23
  • @Louis - the question you are referencing uses Java. Here is another using C# http://stackoverflow.com/questions/18034747/unable-to-load-default-profile-in-chrome-with-selenium-webdriver/18037924 Question here uses JavaScript and the directory structure looks like Mac. Looking at the source - https://code.google.com/p/selenium/source/browse/javascript/node/selenium-webdriver/chrome.js#405 - ```--``` (shouldn't matter, should work with or without)... Thinking about creating an issue here: https://github.com/SeleniumHQ/selenium/issues – Mars Robertson Jul 30 '15 at 14:32
  • @MichalStefanow True, I should have said "quasi-duplicate". – Louis Jul 30 '15 at 14:34

1 Answers1

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

Community
  • 1
  • 1
Mars Robertson
  • 12,673
  • 11
  • 68
  • 89
  • 2
    To select a different profile, say Profile 1, use options.addArguments("profile-directory=Profile 1"); – Glen Pierce Jun 20 '18 at 15:59
  • 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 profile````options.addArguments("user-data-dir=/Users/henry/Documents/POC/Profile 4");```` – Vaibhav_Sharma Feb 09 '22 at 18:46