Unable to interact with selenium webdriver after initializing it with the new service method [Python]

I’m trying to initialize a chrome webdriver with a custom user profile using the following code:

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

options = webdriver.ChromeOptions()
options.add_experimental_option("detach", True)
options.add_argument("--start-maximized")
options.add_argument(r'user-data-dir=C:\Users\{User}\AppData\Local\Google\Chrome\User Data\Profile XY')
service = Service(executable_path=r'C:\Program Files\Google\Chrome\Application\chrome.exe')
driver = webdriver.Chrome(options=options, service=service)

So far so good. Up until this point the code is executed and a new Chrome window pops up with the correct user profile selected. However, everything that comes after the initialization of the webdriver isn’t executed anymore. E.g. the following code won’t be executed.

print("This is a debug msg")
driver.get("https://google.com/")

So my question is, how do i properly interact with the driver after it has been initialized if i cannot use driver.doSomething() anymore?

Any help would be appreciated.

Additional info: using the newest chrome and selenium versions.

See the above code example.

Read more here: Source link