Jide Koso
Jide Koso

Reputation: 425

Selenium and Python3 ChromeDriver raises Message: Can not connect to the Service chromedriver

Please how do get selenium working in this scenerio? I have seen this questions times with fewer or no answers and i hope luck is on my side today.

Let me start by detailing my environment.

  1. I am running MacOS Seirra.
  2. I am using virtualenv/virtualenvwrapper with python3 to run the following.

    from selenium import webdriver
    from selenium.webdriver.common.keys import Keys
    import os
    
    chromedriver = "/usr/local/bin/chromedriver"
    os.environ["webdriver.chrome.driver"] = chromedriver
    
    driver = webdriver.Chrome()
    driver.get("http://www.python.org")
    print(driver.title)
    driver.quit()
    

The lines below were added after i followed example from similar question here

chromedriver = "/usr/local/bin/chromedriver" # i used brew to install chrome to get this path from the command 'which chromedriver'

os.environ["webdriver.chrome.driver"] = chromedriver

Alternatively i downloaded chromedriver directly from github and added the path as follows:

/Users/Me/Downloads/chromedriver

I have triend not passing arguements to the driver but i still get this error.

Traceback (most recent call last):
  File "aicpa.py", line 8, in <module>
    driver = webdriver.Chrome()
  File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/chrome/webdriver.py", line 62, in __init__
    self.service.start()
  File "/Users/Me/.virtualenvs/aicpa/lib/python3.5/site-packages/selenium/webdriver/common/service.py", line 102, in start
    raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver

Complements of the season and thanks in advance.

Upvotes: 0

Views: 3105

Answers (4)

Pocketsand
Pocketsand

Reputation: 1281

I had to remove the quarantine attribute from the file:

xattr -d com.apple.quarantine /path/to/chromedriver

Upvotes: 0

deepstereo
deepstereo

Reputation: 171

In my case adding 127.0.0.1 localhost to hosts file solved the issue.

Upvotes: 0

Andreas Rau
Andreas Rau

Reputation: 336

I didn't test this but please try:

chromedriver = "/usr/local/bin"

os.environ[] simply adds a path variable which has to be a folder and NOT a file.

Upvotes: 1

Lucas Tierney
Lucas Tierney

Reputation: 2563

Have you tried this?

webdriver.Chrome("/usr/local/bin/chromedriver")

Upvotes: 2

Related Questions