selenium.common.exceptions.WebDriverException:消息:即使将127.0.0.1 locahost添加到/ etc / host

时间:2019-04-01 02:03:17

标签: python python-3.x selenium-webdriver

在硒中使用chromedriver打开chrome时出现问题。即使我尝试将firefox与geckodriver一起使用时,问题仍然不断出现。

研究

经过研究,我发现了很多关于stackoverflow的问题,例如:

  1. selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser
  2. Selenium and Python3 ChromeDriver raises Message: Can not connect to the Service chromedriver

...更多我忘了(实际上花了半天时间找到)...

并且在firefox github issue #230中,他们建议我在127.0.0.1 localhost上添加/etc/hosts,但是并不能解决问题。

我使用的程序版本

输出

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\Users\Kevin\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\common\service.py", line 104, 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

代码

from selenium import webdriver
browser = webdriver.Chrome(executable_path="/path/to/chromedriver") # Did not work !!!!!!!

上面的代码暂停了大约8分钟并产生了上面的输出

注释

  • 将可执行文件路径添加到webdriver.Chrome()无法解决该问题。
  • chromedriver.exegeckodriver.exe都添加到PATH也是不可能的。
  • /etc/hosts重置为默认设置无效。
  • 重新启动计算机,就像IT人员说仍然无法修复XD

0 个答案:

没有答案