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

Since there doesn't seem to be a way to use an existing Chrome window, how do I use the Google acc

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
Add a ment  | 

1 Answer 1

Reset to default 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

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")

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742328941a4423317.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信