【问题标题】:selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH with GeckoDriver Selenium Firefoxselenium.common.exceptions.WebDriverException:消息:“geckodriver”可执行文件需要在 GeckoDriver Selenium Firefox 的 PATH 中
【发布时间】:2018-07-11 02:15:29
【问题描述】:

我对 Pycharm 或 Python 的了解不足以解决问题所在。似乎我觉得应该执行这段简单的代码,但我得到一堆乱七八糟的文本,对我没有任何意义。

其他使用 Selenium 的人收到此错误并知道如何修复它? 物理代码 -

"C:\Users\Noah Linton\PycharmProjects\EdgenuityBot\venv\Scripts\python.exe" 
"C:/Users/Noah Linton/PycharmProjects/EdgenuityBot/Edgenuity Bot"
Traceback (most recent call last):
  File "C:\Users\Noah Linton\PycharmProjects\EdgenuityBot\venv\lib\site-
packages\selenium\webdriver\common\service.py", line 76, in start
    stdin=PIPE)
  File "C:\Program Files (x86)\Microsoft Visual 
Studio\Shared\Python36_64\Lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)
  File "C:\Program Files (x86)\Microsoft Visual 
Studio\Shared\Python36_64\Lib\subprocess.py", line 997, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:/Users/Noah Linton/PycharmProjects/EdgenuityBot/Edgenuity Bot", line                         
3, in <module>
driver = webdriver.Firefox()
File "C:\Users\Noah Linton\PycharmProjects\EdgenuityBot\venv\lib\site-
packages\selenium\webdriver\firefox\webdriver.py", line 148, in __init__
self.service.start()
File "C:\Users\Noah Linton\PycharmProjects\EdgenuityBot\venv\lib\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: 'geckodriver' 
executable needs to be in PATH. 


Process finished with exit code 1

执行代码

 from selenium import webdriver

driver = webdriver.Firefox()
driver.get("https://auth.edgenuity.com/Login/Login/Student")
button = driver.find_element_by_id('LoginSubmit')
button.click()

【问题讨论】:

  • 错误是...?请提供确切的错误和相关代码。
  • 对不起!我在中添加了截图
  • Trace back 是 python 返回错误/异常的方式。在此处发布它所说的内容以及相关的 sn-p 代码可能会产生您的答案。
  • 我更新了显示相关代码

标签: python selenium firefox selenium-webdriver geckodriver


【解决方案1】:

对于它可能有什么帮助,回溯的关键部分是

FileNotFoundError: [WinError 2] The system cannot find the file specified

line 3, in <module>
driver = webdriver.Firefox()

selenium.common.exceptions.WebDriverException: Message: 'geckodriver' 
executable needs to be in PATH.

Firefox 网络驱动程序似乎不在您的主程序看到的已定义搜索路径中。有一个名为 geckodriver 的东西不可用。

检查此软件包的安装和配置。请咨询您的班级导师和同学寻求帮助。我怀疑维修是由您当地的设置引起的,超出了我们这里的知识范围。

【讨论】:

    【解决方案2】:

    错误说明了一切:

    selenium.common.exceptions.WebDriverException: Message: 'geckodriver' executable needs to be in PATH. 
    

    这意味着 GeckoDriver 二进制文件不在 Classpath

    使用 Selenium v​​3.x 时,您必须从 url 下载最新的 GeckoDriver 并将其存储在您的系统中,并在启动时提及绝对路径webdriverWeb Browser 会话如下:

    from selenium import webdriver
    
    driver = webdriver.Firefox(executable_path="C:\\path\\to\\geckodriver.exe")
    driver.get("https://auth.edgenuity.com/Login/Login/Student")
    button = driver.find_element_by_id('LoginSubmit')
    button.click()
    

    【讨论】:

    • 成功了!但是,我想补充一点,在 r"C:\\path\\to\\geckodriver.exe 之前应该有一个 r ,以便将路径字符串转换为原始字符串,而不是普通字符串,以便其他人提出类似的问题这个。非常感谢!
    猜你喜欢
    • 2019-06-13
    • 2021-04-15
    • 2020-09-11
    • 2017-03-04
    • 2017-08-03
    • 2018-03-22
    • 1970-01-01
    • 2021-01-26
    • 2020-06-05
    相关资源
    最近更新 更多