How to prevent being signed out of your Google account on a Chrome profile opened in Selenium Python

307 Views Asked by At

I managed to start Selenium with a custom Chrome Profile that is signed into a Google Account using ChromeOptions by changing the location of the Chrome Profile folder in my directory, renaming it to "Default" and omitting the "Default" in the path in the argument (cf. explanation here).

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options

options = Options()
options.add_argument(r"user-data-dir=C:\ChromeProfiles1")

s=Service(r"C:\Users\Administrator\Desktop\chromedriver.exe")
driver = webdriver.Chrome(service=s, options=options)
                          
driver.get(r"https://drive.google.com")

However, as soon as the browser opens, I am signed out of my Google account. It only stays logged in for a split second. Here's a screen capture of it.

Also, I have tried creating new paths to chrome profiles multiple times and only when using it for the first time respectively the icon of the Google account appears for a brief moment. All of the tries after that make it start as "signed out" right away (the way it looks in my recording after the blue icon disappears). Google still seems to realise that the browser is automated; is there a way around this? Can this be fixed by a change to the Chrome profile?

0

There are 0 best solutions below