【发布时间】:2020-02-16 08:47:49
【问题描述】:
我正在尝试使 selenium 与 Firefox 71.00 x64 en-US 一起工作,我输入的代码是:
from selenium import webdriver
browser = webdriver.Firefox()
但是浏览器没有启动,即使我已经将 geckodriver(最新版本可下载)和 firefox.exe 的目录都添加到系统路径中,我仍然会收到此错误:
File "C:\Users\Tommaso\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\common\service.py", line 72, in start
self.process = subprocess.Popen(cmd, env=self.env,
File "C:\Users\Tommaso\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 854, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\Tommaso\AppData\Local\Programs\Python\Python38\lib\subprocess.py", line 1307, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Impossibile trovare il file specificato
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\Tommaso\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\firefox\webdriver.py", line 164, in __init__
self.service.start()
File "C:\Users\Tommaso\AppData\Roaming\Python\Python38\site-packages\selenium\webdriver\common\service.py", line 81, in start
raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH.
【问题讨论】:
-
here 的一些答案可能有用。
-
尝试明确地给出您的 exe 的路径,例如使用 chrome:
driver = webdriver.Chrome(r'C:\Program Files (x86)\Google\Chrome\Application\chromedriver.exe') -
在这种情况下我得到另一个错误,但我确信目录是正确的。
NotADirectoryError: [WinError 267] Nome di directory non valido: 'C:\\Program Files\\Mozilla Firefox\\firefox.exe'
标签: python python-3.x selenium selenium-webdriver