0

The Selenium Chrome Webdriver does not load my default Chrome profile.

I already tried many other Stack Overflow solutions including changing the path (and using the local Chrome App, which gives a 'permission denied' Error).

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options

options = webdriver.ChromeOptions()
options.add_argument("--user-data-dir=~/Library/Application Support/Google/Chrome/Default")
options.add_argument("--profile-directory=Default")

driver = webdriver.Chrome()
driver.get("https://tagmanager.google.com/#/home")

assert "Google Analytics" in driver.title
account_element = driver.find_element_by_css_selector("div.account.card div#149385038 table")
accountPublicId = driver.find_element_by_css_selector("div#149385038 table td.account__public-id")

The result is still the same; it loads only a 'naked' Chrome Webdriver instead of loading the local default profile (I use everyday for work).

Update:

I don't know how or why but now, when I quit Chrome and start Chrome through the Python Script, Google Chrome starts with my profile but does not use the cookies I have in that profile.

I will see if I can add the cookies "manually" with an options.add_arguments.

RonFort
  • 21
  • 7
  • 1
    It's in C# but have you read this? https://stackoverflow.com/questions/50635087/how-to-open-a-chrome-profile-through-user-data-dir-argument-of-selenium – Stephen K Jul 23 '19 at 15:54
  • Actually it's supposed to be written in Python. What would be the right code then? I looked into the wrong article indeed but I don't know what is right then? – RonFort Jul 24 '19 at 07:44
  • you misunderstand me, I'm not saying your code is in C# but the code in the other question I linked is. – Stephen K Jul 24 '19 at 07:58

2 Answers2

0

Try this:

from selenium import webdriver

options = webdriver.ChromeOptions() 
options.add_argument("user-data-dir=C:\\ProfilePath") ##profile path
w = webdriver.Chrome(executable_path="C:\\chromedriver.exe", chrome_options=options)
mk_
  • 164
  • 1
  • 14
  • Unfortunately, it doesn't work either - the problem remains the same. I still have a 'naked' Chrome opening. – RonFort Jul 26 '19 at 13:02
0

you may try this

options.add_argument("user-data-dir=C:\\Test") 

did not add anything to the

options arguments (looking via debugger it was an empty list)

options.arguments.append("user-data-dir=C:/test/") managed to update the list of arguments and it worked.

user11717481
  • 1
  • 9
  • 15
  • 25