0

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.

Community
  • 1
  • 1
Jide Koso
  • 415
  • 5
  • 17
  • So you now have two chromedriver binaries, one in /usr/local/bin/ and one in /Users/Me/Downloads/? Since you start Chrome without defining the path to chromedriver, it will search in PATH. Maybe you didn't add proper rights to the files? Check them, it can be the cause. – monami Dec 08 '16 at 20:30

4 Answers4

2

Have you tried this?

webdriver.Chrome("/usr/local/bin/chromedriver")
Lucas Tierney
  • 2,503
  • 15
  • 13
1

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.

Andreas Rau
  • 338
  • 2
  • 11
  • True. However, he used `webdriver.Chrome()` and this looks up in PATH, and he added `/Users/Me/Downloads/chromedriver` (with filename?) to it. But, if it weren't on PATH, it would give a "WebDriverException: Message: 'chromedriver' executable needs to be available in the path", wouldn't it? – monami Dec 08 '16 at 23:16
  • if /Users/Me/Downloads/chromedriver is added to the path it will try to look in the folder chromedriver. As chromedriver is a file and not a folder this will fail. The problem is that he looked up chromedriver with 'which' outputing the path to the file not the path to the folder containing the file – Andreas Rau Dec 09 '16 at 09:12
  • if my solution is not working please check if the chromedriver is marked as executable. If not run 'sudo chmod a+x chromedriver'. – Andreas Rau Dec 09 '16 at 09:18
  • The problem was that I was using VPN and when i disconnected the vpn everything worked. – Jide Koso Dec 09 '16 at 16:27
0

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

deepstereo
  • 131
  • 1
  • 3
0

I had to remove the quarantine attribute from the file:

xattr -d com.apple.quarantine /path/to/chromedriver
Pocketsand
  • 1,261
  • 10
  • 15