Reputation: 47
I'm trying to make selenium open a user profile so i can automate stuff in my google accounts without having to login every time, with the code below i have managed to open chrome but as soon as it opens, it crashes, here's my code. (My OS is MacOS Ventura)
My chromdriver
and my Google Chrome are in the same version
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
service = Service("/usr/local/bin/chromedriver")
ch_options = Options() # options
ch_options.add_argument("user-data-dir=/Users/matheus/Library/Application Support/Google/Chrome")
ch_options.add_argument("--profile-directory=Profile 2")
driver = webdriver.Chrome(service=service, options=ch_options)
driver.get("https://gmail.com")
Here's the crash log
Traceback (most recent call last):
File "/Users/matheus/dev/work-automations/main.py", line 12, in <module>
driver = webdriver.Chrome(service=service, options=ch_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
super().__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 92, in __init__
super().__init__(
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 272, in __init__
self.start_session(capabilities, browser_profile)
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 364, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/remote/webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "/Users/matheus/dev/work-automations/venv/lib/python3.11/site-packages/selenium/webdriver/remote/errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(chrome not reachable)
(The process started from chrome location /Applications/Google Chrome.app/Contents/MacOS/Google Chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
0 chromedriver 0x000000010276aa88 chromedriver + 4123272
1 chromedriver 0x00000001026f6778 chromedriver + 3647352
2 chromedriver 0x00000001023b8ac4 chromedriver + 248516
3 chromedriver 0x00000001023dc2a4 chromedriver + 393892
4 chromedriver 0x00000001023d8858 chromedriver + 378968
5 chromedriver 0x00000001024125a0 chromedriver + 615840
6 chromedriver 0x00000001024121d8 chromedriver + 614872
7 chromedriver 0x00000001023e2b10 chromedriver + 420624
8 chromedriver 0x00000001023e3c30 chromedriver + 425008
9 chromedriver 0x000000010273cae4 chromedriver + 3934948
10 chromedriver 0x000000010273ff24 chromedriver + 3948324
11 chromedriver 0x0000000102740508 chromedriver + 3949832
12 chromedriver 0x0000000102746b30 chromedriver + 3975984
13 chromedriver 0x0000000102740b24 chromedriver + 3951396
14 chromedriver 0x000000010271b71c chromedriver + 3798812
15 chromedriver 0x000000010275d2f0 chromedriver + 4068080
16 chromedriver 0x000000010275d444 chromedriver + 4068420
17 chromedriver 0x0000000102771450 chromedriver + 4150352
18 libsystem_pthread.dylib 0x000000018421a06c _pthread_start + 148
19 libsystem_pthread.dylib 0x0000000184214e2c thread_start + 8
Process finished with exit code 1
Upvotes: 0
Views: 1357
Reputation: 96
The path provided for Profile 2 seems to be the original one located in library.
If your browser is open at the same time it can cause conflicts. I recommend to make a copy of the original folder and use it instead.
In case you don't know how to access it:
Finder > Go > Press Option Key (Library appears) > Library > Application Support > Google > Chrome > Profile 2
So I have modified your code, and it should look like this : I let you change the path according to where you will place your Profile copy.
from selenium import webdriver
ch_options = webdriver.ChromeOptions()
ch_options.add_argument("--user-data-dir=/Users/matheus/desktop/Selenium Profile/Profile 2")
driver = webdriver.Chrome(options=ch_options)
driver.get("https://gmail.com")
Hope this helps you, Best
Upvotes: 1