0

By following this answer from StackOverflow I was trying to connect to my existing Chrome browser in Selenium, but every time I am getting this error:

Exception has occurred: MaxRetryError
HTTPConnectionPool(host='localhost', port=52093): Max retries exceeded with url: /session/a706d3e0009e8d794418190aa6e026e7/window (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x000002491F52A920>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))

During handling of the above exception, another exception occurred:


During handling of the above exception, another exception occurred:

  File "scrapper.py", line 9, in <module>
    driver.close()   # this prevents the dummy browser

here is my code

from selenium import webdriver

driver = webdriver.Chrome()

url = driver.command_executor._url       #"http://127.0.0.1:60622/hub"
session_id = driver.session_id            #'4e167f26-dc1d-4f51-a207-f761eaf73c31'

driver = webdriver.Remote(command_executor=url,desired_capabilities={})
driver.close()   # this prevents the dummy browser
driver.session_id = session_id

driver.get("https://www.google.com")

How can I fix this.

thank you.

resun
  • 25
  • 6

1 Answers1

0

it seems like the code that you are using is from an older question and is legacy.

This works:

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager


service=Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=service)


url = "https://www.google.com"

driver.get(url)

D.L
  • 4,339
  • 5
  • 22
  • 45
  • This opens a new chrome window and opens the URL in that window. I am trying to use an existing chrome window. – resun Sep 30 '22 at 19:58