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

时光总嘲笑我的痴心妄想 提交于 2020-05-01 14:05:59

问题


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.


回答1:


Have you tried this?

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



回答2:


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.



来源:https://stackoverflow.com/questions/41047957/selenium-and-python3-chromedriver-raises-message-can-not-connect-to-the-service

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!