我的本地Chrome 67 Python 3.5.0 Selenium 3.12.0具有以下环境
我已经下载了2.39版的chromedriver
我有.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()
我收到以下错误。
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
我也尝试过使用其他网络驱动程序,如geckodriver.exe仍然相同的错误。
请帮助我解决此错误。
谢谢!
乍一看,您的代码试用似乎在 参数 execute_path* 的 值 中存在一个小错误。代替它应该是: __*hromedriver.exe
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')
此错误消息…
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service chromedriver.exe
…表示程序/脚本无法 ChromeDriverService 通过 chromedriver.exe 启动/产生。
ChromeDriverService
该错误的潜在原因可能是:
127.0.0.1 localhost
/etc/hosts
Windows操作系统 -添加127.0.0.1 localhost到/etc/hosts
Mac OSX- 确保输入以下内容:
127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost fe80::1%lo0 localhost
根据selenium.common.exceptions.WebDriverException中的讨论:消息:无法连接到服务geckodriver:
如何将主机文件重置为默认值