Home > front end >  What is preventing my Chrome profile from working with Selenium in Python?
What is preventing my Chrome profile from working with Selenium in Python?

Time:11-12

I am trying to use Python to automate a number of work processes that primarily take place in an online content management system, and to access the CMS, I need to be logged into my work profile on Chrome. While I could sign in once Chromedriver is open, I would have to approve the login on my authenticator each time, somewhat defeating the purpose of automation.

I am using the following code for opening Chromedriver and attempting to load my regular Chrome profile. However, while the rest of the code works as intended, it does not load my profile and I am unsure why.

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

options = Options()
options.add_argument("--start-maximized")
options.add_argument("--user-data-dir=C:\\Users\\Saul\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome("C:\\Users\\Saul\\Downloads\\chromedriver_win32\\chromedriver.exe", options=options)
driver.get("https://myaccount.google.com/")
while(True):
    pass

I do get the following error while running the code, but I don't believe this is affecting my issue.

C:\Users\Saul\PycharmProjects\OnlineAutomation\main.py:12: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Chrome("C:\\Users\\Saul\\Downloads\\chromedriver_win32\\chromedriver.exe", options=options)

CodePudding user response:

Your question is not related to the error you mentioned.

For the error - 'DeprecationWarning: executable_path has been deprecated, please pass in a Service object', you have to use Service:

from selenium.webdriver.chrome.service import Service

driver = webdriver.Chrome(service=Service("C:\\Users\\Saul\\Downloads\\chromedriver_win32\\chromedriver.exe"), options=options)

For the Chrome profile issue, you have to mention the profile path like below:

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

options.add_argument("--profile-directory=Default")

CodePudding user response:

If your website has MFA enabled, you might be able to use SeleniumBase (a Python framework), which has methods for handling MFA Login:

  • Related