smaillis
smaillis

Reputation: 358

How to have selenium logged in to websites on start up with python

When you open chrome manually, you usually expect your account to stay logged in from last time right? How do you do that with selenium and python? Currently I'm loading the user profile via the following, and the 'current user' is 'not signed in'

options = webdriver.ChromeOptions()
options.add_argument("user-data-dir=C:\\Users\\ME\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
browser = webdriver.Chrome(chrome_options=options, 
    executable_path='C:\chromedriver.exe')

What am I missing?

Upvotes: 0

Views: 201

Answers (2)

smaillis
smaillis

Reputation: 358

Found the problem. After I check chrome://version in the python launched instance. The profile there was actually

'C:\Users\ME\AppData\Local\Google\Chrome\User Data\Default\Default'

Notice the two default at the end. To solve it, remove the default for 'user-data-dir' i.e.

options.add_argument("user-data-dir=C:\\Users\\ME\\AppData\\Local\\Google\\Chrome\\User Data\\")

Upvotes: 1

josifoski
josifoski

Reputation: 1726

Hm, looks nice your side
Try adding this 2 lines

options.add_experimental_option("excludeSwitches", ['enable-automation']) 
options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors", "safebrowsing-disable-download-protection", "safebrowsing-disable-auto-update", "disable-client-side-phishing-detection"])

Upvotes: 0

Related Questions