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.
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.
Share Improve this question asked Feb 11, 2021 at 18:19 fr0stbytefr0stbyte 512 silver badges9 bronze badges 4- You can do this by saving the cookies after you login, then later you can load them in your script. See this answer stackoverflow./questions/15058462/… – Jortega Commented Feb 11, 2021 at 18:46
- lots of answers on SO: stackoverflow./a/31063104/1387701 – DMart Commented Feb 11, 2021 at 18:52
- Also: "going to be used by mutliple users"? I'm not sure selenium is the tool you want to use. – DMart Commented Feb 11, 2021 at 18:53
- If Selenium may not be the right tool, then what do you remend? The functionality I require is to open links and click on elements on pages like buttons. I use node.js, by the way. – fr0stbyte Commented Feb 11, 2021 at 19:02
1 Answer
Reset to default 9var 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
copy the user dir folder pletely 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")