所以我是一个python新手,并且对WebDriver和它可能的应用程序产生了兴趣。因此,我编写这篇文章只是为了测试是否安装了所有必需的库。
from selenium import webdriver
import time
driver = webdriver.Chrome(executable_path= r'chromedriver.exe')
driver.get('http://www.google.com')一旦我写了python3 nameOfCode.py,结果就是一个错误,就像它经常发生的那样。错误是
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
发布于 2019-04-03 01:41:52
最后一行说明了一切...
'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”文件,使其包含可执行文件的位置,或者放入:
PATH="${PATH}:/some/other/directory:/another/place/scripts/live:"
export $PATH.bash_profile文件中的某个位置
https://stackoverflow.com/questions/55480392
复制相似问题