I'm trying to connect selenium to an already open Google Chrome window in the following way:
options.add_experimental_option('debuggerAddress', 'localhost:9112')
options.add_argument('--disable-blink-features=AutomationControlled')
options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')
options.add_argument('--disable-browser-side-navigation')
options.add_argument('--disable-gpu')
options.add_argument('enable-automation')
self.d = webdriver.Chrome(executable_path=r'C:\Users\Administrator\Desktop\chromedriver.exe', options=options)
By first calling Google Chrome from the command line:
chrome.exe --remote-debugging-port=9112 --user-data-dir="C:\selenum\AutomationProfile"
At first it's working fine, driver does his thing, but as soon as I logged out of the server and, of course, can't see browser window, Selenium also stops seeing it and raising errors
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable (Session info: chrome=105.0.5195.102)
no such window: target window already closed from unknown error: web view not found (Session info: chrome=105.0.5195.102)
The interesting thing is that when I switch back to the remote machine, the browser loads and continues to work. I also tried to add
options.add_experimental_option("detach", True)
But it didn't solve the problem. When I run selenium in normal way without command line, debugging and other stuff then it works stable, but I need to handle an already opened Google Chrome window.