fr0stbyte
fr0stbyte

Reputation: 51

How to use Chrome profile in Selenium (selenium-webdriver) JavaScript

Since there doesn't seem to be a way to use an existing Chrome window, how do I use the Google account (and all settings and passwords) of the user in the window that Selenium opens? Selenium seems to open windows for itself, but without a Google account, which is an essential part to my program.

My program is very time sensitive, so it needs to be logged in to the websites it accesses automatically, and the program is going to be used by multiple users.

Upvotes: 1

Views: 6733

Answers (1)

PDHide
PDHide

Reputation: 19929

var webdriver = require("selenium-webdriver");
var chrome = require("selenium-webdriver/chrome");
var options = new chrome.Options();
    
options.addArguments("user-data-dir=C:\\Users\robert.car\\AppData\\Local\\Google\\Chrome\\User Data")
    
options.addArguments("profile-directory=Profile 1")

var driver = let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(options)
.build();

user-data-dir considers profile as default , and you don't have to specify that . If its something else specify it through profile-directory argument

Step to create a profile:

open : chrome://version in address bar

enter image description here

copy the user dir folder completely to eg c:\tmp\newdir

open the copied user data (newdir) and search for folder called Default . This is the profile folder.

rename the Default folder as "Profile 1"

Now to use this :

options.addArguments("user-data-dir=c:\\tmp\\newdir")

options.addArguments("profile-directory=Profile 1")

Upvotes: 9

Related Questions