python – Selenium + webdriver_manager results in WebDriverException: Message: Can not connect to the Service

**Solution: Selenium’s new tool known as SeleniumManager will do what ChromeDriverManager used to do. No need to use webdriver_manager **


options = Options()
options.add_argument('--no-sandbox')  # Run Chrome without the sandbox
options.add_argument('--headless')  # Run Chrome in headless mode (no GUI)

driver = webdriver.Chrome(options=options)

I’m trying to run the code below, but getting the following error:

WebDriverException: Message: Can not connect to the Service /Users/abc/.wdm/drivers/chromedriver/mac64/115.0.5790.114/chromedriver-mac-arm64/chromedriver

from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
from selenium.webdriver.chrome.options import Options


options = Options()
options.add_argument('--no-sandbox')  # Run Chrome without the sandbox
options.add_argument('--headless')  # Run Chrome in headless mode (no GUI)
options.binary_location="/Applications/Google Chrome.app/Contents/MacOS/Google Chrome"

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()), options = options)

I’ve done the following:

  1. Ensuring ChromeDriver binary has executable permission for the non-root user.
  2. Ensure that /etc/hosts file contains 127.0.0.1 localhost
  3. ChromeDriver executable file is the correct version for the installed version of Chrome (see image below)
  4. Verify that the path to the ChromeDriver executable is correct: /Users/abc/.wdm/drivers/chromedriver/mac64/115.0.5790.114/chromedriver-mac-arm64/chromedriver
  5. I’ve added /Users/abc/.wdm/drivers/chromedriver/ as a path environment variable.

enter image description here

Any ideas?

Read more here: Source link