2

For context:

• Ventura 13.4.1

• Python 3.11.4

• Running in Jupyter Notebook in VSCode

• Selenium 4.11.2

I was able to run a Selenium script on an existing webpage, and then Selenium was unable to connect to Chrome because WebDriverException: Message: Unable to obtain Selenium Manager (not sure why it suddenly stopped working, no packages were updated). I installed Selenium 4.11.2 from miniconda, but this bug report said to try the pip release instead.

So then I couldn't connect to Chrome again. ChromeDriver was installed by brew and chromedriver --port=9222 says

Starting ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052}) on port 9222 
ChromeDriver was started successfully.

I also run /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome -–remote-debugging-port=9222 and it opens a new Chrome window.

This is the beginning of my Selenium script:

from bs4 import BeautifulSoup
import requests
import pandas as pd
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager

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

chromeoptions = Options()
chromeoptions.debugger_address='127.0.0.1:9222'
driver = webdriver.Chrome(service=Service(ChromeDriverManager(driver_version='114.0.5735.90').install()), options=chromeoptions)

and it throws Message: unknown error: cannot connect to chrome at 127.0.0.1:9222 from chrome not reachable.

Both ChromeDriver and Google Chrome were added to my PATH

export PATH=$PATH:/opt/homebrew/Caskroom/chromedriver/114.0.5735.90/chromedriver
export PATH=$PATH:/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome

as confirmed by echo $PATH: /opt/homebrew/Caskroom/chromedriver/114.0.5735.90/chromedriver:/Applications/Google Chrome.app/Contents/MacOS/Google Chrome

UPDATE: Same error after

chromeoptions = Options()
chromeoptions.add_experimental_option(name='debuggerAddress', value='127.0.0.1:9222')
# chromeoptions.debugger_address='127.0.0.1:9222'
driver = webdriver.Chrome(options=chromeoptions)
driver.get("https://www.linkedin.com")

, ./selenium-manager --browser chrome --debug returns

DEBUG   Checking chromedriver in PATH
DEBUG   Running command: chromedriver --version
DEBUG   Output: "ChromeDriver 114.0.5735.90 (386bc09e8f4f2e025eddae123f36f6263096ae49-refs/branch-heads/5735@{#1052})"
DEBUG   Running command: which chromedriver
DEBUG   Output: "/opt/homebrew/bin/chromedriver"
DEBUG   Found chromedriver 114.0.5735.90 in PATH: /opt/homebrew/bin/chromedriver
DEBUG   chrome detected at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
DEBUG   Using shell command to find out chrome version
DEBUG   Running command: /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --version
DEBUG   Output: "Google Chrome 114.0.5735.198 "
DEBUG   Detected browser: chrome 114.0.5735.198
DEBUG   Required driver: chromedriver 114.0.5735.90
INFO    Driver path: /opt/homebrew/bin/chromedriver
INFO    Browser path: /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

1 Answers1

0

This error message...

Message: unknown error: cannot connect to chrome at 127.0.0.1:9222 from chrome not reachable

...implies that ChromeDriver was unable to connect to the binary due to incompatibility issues.


Solution with Selenium v4.6+ versions

As you are using Selenium v4.11.2 you no more require to use WebDriverManager.

In such cases Selenium Manager can come to your rescue. Selenium Manager which is now fully integrated with Selenium can silently download the matching ChromeDriver in the background and execute the test.

So your effective code block can be:

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

chromeoptions = Options()
chromeoptions.debugger_address='127.0.0.1:9222'
driver = webdriver.Chrome(options=chromeoptions)

References

You can find a couple of relevant detailed discussions in:

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I got the same error (in updated post), is it possible that `ChromeDriver` isn't communicating with `chrome`? I should note that I'm trying to run the script on an already open webpage. – Vijay Tripathi Aug 07 '23 at 14:53