Selenium和Python3 ChromeDriver发出消息:无法连接到chromedri服务

2024-10-02 00:28:58 发布

您现在位置:Python中文网/ 问答频道 /正文

请问如何让硒在这种环境下发挥作用?我已经看过很多次这样的问题了,很少有人回答,我希望今天好运在我这边。在

让我先详细介绍一下我的环境。在

  1. 我正在运行MacOS Seirra。在
  2. 我正在使用virtualenv/virtualenvwrapper与python3一起运行 跟随。在

    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()
    

下面的行是在我遵循类似问题here中的示例之后添加的

^{pr2}$

或者,我直接从github下载chromedriver并添加路径如下:

/Users/Me/Downloads/chromedriver

我已经三年没有把争论传给司机了,但我还是犯了这个错误。在

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

作为本季的补充,请提前致谢。在


Tags: infrompyimport环境driverseleniumline
2条回答

你试过这个吗?在

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

我没有测试这个,但请尝试:

chromedriver = "/usr/local/bin"

和13;
和13;

在操作系统环境[]只需添加一个路径变量,该变量必须是文件夹而不是文件。在

相关问题 更多 >

    热门问题