首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >代码不能将chromedriver.exe识别为文件

代码不能将chromedriver.exe识别为文件
EN

Stack Overflow用户
提问于 2019-04-03 01:22:18
回答 1查看 191关注 0票数 0

所以我是一个python新手,并且对WebDriver和它可能的应用程序产生了兴趣。因此,我编写这篇文章只是为了测试是否安装了所有必需的库。

代码语言:javascript
复制
from selenium import webdriver
import time

driver = webdriver.Chrome(executable_path= r'chromedriver.exe')
driver.get('http://www.google.com')

一旦我写了python3 nameOfCode.py,结果就是一个错误,就像它经常发生的那样。错误是

代码语言:javascript
复制
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
  File "testSelenium.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path= mac/Desktop/chromedriver.exe)
NameError: name 'mac' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
  File "testSelenium.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path= Desktop/chromedriver.exe)
NameError: name 'Desktop' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
  File "testSelenium.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path= chromedriver.exe)
NameError: name 'chromedriver' is not defined
macs-MacBook-Pro:Desktop mac$ python3 testSelenium.py
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 76, in start
    stdin=PIPE)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/subprocess.py", line 1344, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver.exe': 'chromedriver.exe'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "testSelenium.py", line 5, in <module>
    driver = webdriver.Chrome(executable_path= r'chromedriver.exe')
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 73, in __init__
    self.service.start()
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/common/service.py", line 83, in start
    os.path.basename(self.path), self.start_error_message)
selenium.common.exceptions.WebDriverException: Message: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

如果这太多了,很抱歉:)) Dario

EN

回答 1

Stack Overflow用户

发布于 2019-04-03 01:41:52

最后一行说明了一切...

代码语言:javascript
复制
'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home

如果您使用的是Windows:

您需要在名为PATH的环境变量中添加"chromedriver.exe“的位置。您应该能够通过开始菜单搜索(搜索:环境变量)找到该对话框,然后找到名为PATH的变量(不区分大小写)。如果它不存在,就创建它。此变量的内容是由分号分隔的文件夹位置列表,其中需要包含"chromedriver.exe“的文件夹。

如果你用的是Mac电脑:(我没有,所以我不能确认这些方法)

编辑“/etc/path”文件,使其包含可执行文件的位置,或者放入:

代码语言:javascript
复制
PATH="${PATH}:/some/other/directory:/another/place/scripts/live:"

export $PATH

.bash_profile文件中的某个位置

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55480392

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档