1

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.

fr0stbyte
  • 51
  • 2
  • 8
  • You can do this by saving the cookies after you login, then later you can load them in your script. See this answer https://stackoverflow.com/questions/15058462/how-to-save-and-load-cookies-using-python-selenium-webdriver – Jortega Feb 11 '21 at 18:46
  • lots of answers on SO: https://stackoverflow.com/a/31063104/1387701 – DMart Feb 11 '21 at 18:52
  • Also: "going to be used by mutliple users"? I'm not sure selenium is the tool you want to use. – DMart Feb 11 '21 at 18:53
  • If Selenium may not be the right tool, then what do you recommend? The functionality I require is to open links and click on elements on pages like buttons. I use node.js, by the way. – fr0stbyte Feb 11 '21 at 19:02

1 Answers1

9
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")
PDHide
  • 18,113
  • 2
  • 31
  • 46