I basically want to set my default profile in the Selenium WebDriver. The same code was working before I reset my window, but after resetting, it gives an error. Here is the code.
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
chrome_userdata_dir = 'C:\\Users\\abdul\\AppData\\Local\\Google\\Chrome\\User Data\\Default'
option = Options()
option.add_argument(f"--user-data-dir={chrome_userdata_dir}")
option.add_argument('--profile-directory=Default')
driver = Chrome(service=Service(ChromeDriverManager().install()), options=option)
If I run it now, it does not open Chrome with the default profile. It opens it casually, like without a default profile. If I change the path of chrome_user_dir to the following, it gives an error but open chrome with default profile.
chrome_userdata_dir = 'C:\\Users\\abdul\\AppData\\Local\\Google\\Chrome\\User Data'
The error logs are following
Opening in existing browser session.
Traceback (most recent call last):
File "E:\LinuxData\Documents\TwitchVideoAutomator\main.py", line 135, in <module>
automate_yt_pals(_headless)
File "E:\LinuxData\Documents\TwitchVideoAutomator\subpal_subscribers\automate_yt_pals.py", line 56, in automate_yt_pals
driver = Chrome(service=Service(path), options=option)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 80, in __init__
super().__init__(
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 104, in __init__
super().__init__(
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 286, in __init__
self.start_session(capabilities, browser_profile)
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 378, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\remote\webdriver.py", line 440, in execute
self.error_handler.check_response(response)
File "E:\LinuxData\Documents\TwitchVideoAutomator\venv\Lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 245, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited normally.
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
Stacktrace:
Backtrace:
(No symbol) [0x005B37D3]
(No symbol) [0x00548B81]
(No symbol) [0x0044B36D]
(No symbol) [0x0046B7EF]
(No symbol) [0x00466FC9]
(No symbol) [0x004A1ED5]
(No symbol) [0x004A1B2C]
(No symbol) [0x0049B216]
(No symbol) [0x00470D97]
(No symbol) [0x0047253D]
GetHandleVerifier [0x0082ABF2+2510930]
GetHandleVerifier [0x00858EC1+2700065]
GetHandleVerifier [0x0085C86C+2714828]
GetHandleVerifier [0x00663480+645344]
(No symbol) [0x00550FD2]
(No symbol) [0x00556C68]
(No symbol) [0x00556D4B]
(No symbol) [0x00560D6B]
BaseThreadInitThunk [0x76B27D69+25]
RtlInitializeExceptionChain [0x77AFB74B+107]
RtlClearBits [0x77AFB6CF+191]
Well, one more thing to mention is that I upgraded my Python version from 3.9 to 3.11, the latest version. I hope all this information will help trace down the error.
Using:
Python3.11, selenium==4.8.2, webdriver-manager==3.8.5
More Info the chrome://version shows profile path as follow:
Profile Path: C:\Users\abdul\AppData\Local\Google\Chrome\User Data\Default
Edit: It look like the versions of chrome driver and chrome not matching Only available driver on chrome driver site is:
My chrome version