I am trying to open the Selenium Chromedriver with a predefined userprofile. The problem is that sometimes I want to run this in visible-mode while using chrome on my own in the meantime - which I cant get to work.
Chrome version: Version 114.0.5735.91 (Official Build) (64-bit)
This is my code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
options = webdriver.ChromeOptions()
options.add_argument(r"--user-data-dir=C:/Users/<User>/AppData/Local/Google/Chrome/User Data")
options.add_argument(r"--profile-directory={}".format("Profile 5"))
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
Upon execution, chrome opens and I see that I am logged into userprofile 5. However after about two seconds. I get the following exception (while the opened selenium browser keeps open):
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.)
When switching into headless mode via
options.add_argument('headless')
everything works apparently (at least I dont get an exception).
Also when opening in non-headless, but without userprofile everything works.
Is there a way to open a non-headless selenium chromedriver with a user-profile while still being able to regularly browse in the normal chrome browser? Thanks for any help!