简体   繁体   English

selenium.common.exceptions.WebDriverException:消息:打开chrome浏览器时无法连接到服务chromedriver.exe

[英]selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe while opening chrome browser

I have following environment at my local Chrome 67 Python 3.5.0 Selenium 3.12.0 我的本地Chrome 67 Python 3.5.0 Selenium 3.12.0具有以下环境

I have downloaded chromedriver with version 2.39 我已经下载了版本2.39的chromedriver

I have .py file as follows 我有.py文件,如下

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path="hromedriver.exe")
driver.get('http://www.google.com')
time.sleep(5)
search_box = driver.find_element_by_name('q')
search_box.send_keys('Python')
search_box.submit()
time.sleep(5)
driver.quit()

I am getting following error. 我收到以下错误。

C:\Python354\python.exe D:/formf.py
Traceback (most recent call last):
  File "D:/PCPNDT/form.py", line 4, in <module>
    driver = webdriver.Chrome(executable_path="chromedriver.exe")  # Optional argument, if not specified will search path.
  File "C:\Python354\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 68, in __init__
    self.service.start()
  File "C:\Python354\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.exe

I also tried with other webdriver like geckodriver.exe still same error. 我也尝试过使用其他网络驱动程序,例如geckodriver.exe仍然是相同的错误。

Please help me out to resolve this error. 请帮助我解决此错误。

Thanks! 谢谢!

At a first glance to your code trial it seems there is a minor bug in the value of the argument executable_path . 乍一看,您的代码试用似乎在参数 execute_path中存在一个小错误。 Instead of hromedriver.exe it should have been: 代替hromedriver.exe它应该是:

# Windows OS
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
# Linux OS
driver = webdriver.Chrome(executable_path='/path/to/chromedriver')

This error message... 此错误消息...

selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe

...implies that the the program/script was unable to initiate/spawn the ChromeDriverService through chromedriver.exe . ......意味着程序/脚本无法启动/产卵ChromeDriverService通过chromedriver.exe。

The potential reason for the error can be: 该错误的潜在原因可能是:

  • Due to missing the entry 127.0.0.1 localhost in /etc/hosts 由于缺少/etc/hosts的条目127.0.0.1 localhost

Solution

  • Windows OS - Add 127.0.0.1 localhost to /etc/hosts Windows操作系统 -将127.0.0.1 localhost /etc/hosts添加到/etc/hosts

  • Mac OSX - Ensure the following entries: Mac OSX-确保输入以下内容:

     127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost 

References 参考

As per the discussion in selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service geckodriver : 根据selenium.common.exceptions.WebDriverException中的讨论:消息:无法连接到服务geckodriver

  • Selenium does not require 127.0.0.1 localhost to be explicitly set in the host file. Selenium不需要在主机文件中显式设置127.0.0.1 localhost
  • However it is mandatory requirement to map localhost to the IPv4 local loopback (127.0.0.1) 但是,必须将本地主机映射到IPv4本地环回(127.0.0.1)
  • The mechanism of this mapping does not have to be through the hosts file always. 这种映射的机制不必总是通过hosts文件。
  • On Windows OS systems it is not mapped in the hosts file at all (resolving localhost is done by the DNS resolver). Windows OS系统上,它根本没有映射到hosts文件中(解析localhost由DNS解析器完成)。

TL;DR TL; DR

How to reset the Hosts file back to the default 如何将主机文件重置为默认值

You've made a mistake into the executable address : 您在可执行文件地址中犯了一个错误:

driver = webdriver.Chrome(executable_path="hromedriver.exe")

It should be : 它应该是 :

driver = webdriver.Chrome(executable_path="chromedriver.exe")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 selenium.common.exceptions.WebDriverException:消息:无法连接到服务。/drivers/chromedriver.exe - selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service ./drivers/chromedriver.exe selenium.common.exceptions.WebDriverException: 消息:无法通过 Selenium Python 使用 ChromeDriver Chrome 连接到服务错误 - selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service error using ChromeDriver Chrome through Selenium Python 为 Windows - selenium.common.exceptions.WebDriverException 安装 Chromedriver:消息:“chromedriver.exe”可执行文件需要在 PATH 中 - Installing Chromedriver for Windows - selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH selenium.common.exceptions.WebDriverException:消息:服务 chromedriver 意外退出 - selenium.common.exceptions.WebDriverException: Message: Service chromedriver unexpectedly exited selenium.common.exceptions.WebDriverException:消息:&#39;无法连接到GhostDriver&#39; - selenium.common.exceptions.WebDriverException: Message: 'Can not connect to GhostDriver' selenium.common.exceptions.WebDriverException:消息:Linux 上的 ChromeDriver Selenium Python 服务 /usr/bin/google-chrome 意外退出 - selenium.common.exceptions.WebDriverException: Message: Service /usr/bin/google-chrome unexpectedly exited with ChromeDriver Selenium Python on Linux selenium.common.exceptions.WebDriverException:消息:使用 find_element_by_id Selenium 和 ChromeDriver 时出现 chrome 无法访问错误 - selenium.common.exceptions.WebDriverException: Message: chrome not reachable error while using find_element_by_id Selenium with ChromeDriver selenium.common.exceptions.WebDriverException:消息:未知错误:Chrome无法启动:使用ChromeDriver Chrome和Selenium异常退出 - selenium.common.exceptions.WebDriverException: Message: unknown error: Chrome failed to start: exited abnormally with ChromeDriver Chrome and Selenium selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用带有Selenium Python的ChromeDriver Chrome创建Chrome进程 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create Chrome process with ChromeDriver Chrome with Selenium Python selenium.common.exceptions.WebDriverException:消息:未知错误:无法使用 ChromeDriver Chrome Selenium 创建 Chrome 进程错误 - selenium.common.exceptions.WebDriverException: Message: unknown error: Failed to create a Chrome process error with ChromeDriver Chrome Selenium
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM