How to utilize saved Chrome password to implement an auto-login script, so that I don't have to put plain-text password in the script?

Viewed 286

The passwords are in my default Chrome profile, which is also what I use for regular browsing. In Selenium, I tried the following

options.add_argument('user-data-dir=/Users/{user}/Library/Application Support/Google/Chrome/')

But it complains

selenium.common.exceptions.InvalidArgumentException: Message: invalid argument: user data directory is already in use, please specify a unique value for --user-data-dir argument, or don't use --user-data-dir

However I need to have a browser with the default --user-data-dir open to do my regular browsing. Is there a way to resolve this conflict, e.g. have my manually-opened session and the Selenium-opened session share a --user-data-dir? Or have the Selenium-opened session attach to my manually-opened session?

If it is not possible, one compromise I could make is to let Selenium use a different --user-data-dir. As a one time work, I can first let Chrome save the passwords for the few websites that I care about. However, it seems that when I use a different --user-data-dir, the opened browser session no longer enables password storing.

I also tried the TestCafe tool, but it also seems to open a non-default profile.

1 Answers

TestCafe allows you to use the current Chrome profile for testing purposes. As stated in the documentation:

If you need to start a browser with the current user profile, you can do this by specifying the :userProfile flag after the browser alias.

Please refer to the following article to get details: https://devexpress.github.io/testcafe/documentation/using-testcafe/common-concepts/browsers/user-profiles.html

Or you can use the --user-data-dir flag to specify a custom user profile directory: testcafe "chrome --user-data-dir=<path>" test.js.

Related