【问题标题】:Geckodriver NOT recognized despite being in System PATH [duplicate]尽管位于系统路径中,但 Geckodriver 无法识别 [重复]
【发布时间】:2020-07-09 13:45:27
【问题描述】:

总结: Geckodriver 似乎无法识别,尽管它已在系统路径中准确设置

当前系统配置:

  • 操作系统:Windows 10;版本:1909;操作系统版本:18363.752;系统类型:64位操作系统 Windows System Info

  • 已安装 Microsoft Visual Studio 可再发行组件 运行时:vc_redist.x64.exe

  • 用户环境变量值:“C:\Users\PCUserName\AppData\Local\Programs\Python\Python38\Scripts\;C:\Users\PCUserName\AppData\Local\Programs\Python\Python38\; %IntelliJ IDEA 社区版%;C:\Program Files\Java\jdk-13.0.1\bin;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Development\Selenium Resources\Selenium Drivers\geckodriver.exe; C:\Development\Selenium Resources\Selenium Drivers\chromedriver.exe;C:\Development\Selenium Resources\Selenium Drivers\;C:\Development\Selenium Resources\Selenium Drivers;C:\Windows\System32\WindowsPowerShell\v1.0 \;C:\Program Files\Git\cmd;C:\Program Files\Microsoft VS Code\bin;"

  • 系统环境变量值:“%path%;C:\Development\Selenium Resources\Selenium Drivers;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\Ruby26- x64\bin;C:\Program Files (x86)\Razer Chroma SDK\bin;C:\Program Files\Razer Chroma SDK\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\ Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Program Files\Java\jre1.8.0_221 \bin\javaw.exe;C:\Program Files\Java\jdk-12.0.2\bin;C:\Users\PCUserName\AppData\Local\Programs\Python\Python38;C:\Users\PCUserName\AppData\Local \Programs\Python\Python38\Scripts;C:\Development\Selenium Resources\Selenium Drivers\;C:\Development\Selenium Resources\Selenium Drivers\chromedriver.exe;C:\Development\Selenium Resources\Selenium Drivers\geckodriver.exe ;"

  • 保存 Selenium 驱动程序的目录:C:\Development\Selenium Resources\Selenium Drivers Selenium Drivers Directory

  • 已安装的 Firefox 浏览器版本:74.0(64 位)

  • 已安装 Geckodriver 版本:geckodriver-v0.26.0-win64.zip 来自此处:https://github.com/mozilla/geckodriver/releases

  • Github 项目(最新):https://github.com/cikent/Selenium-Projects/tree/master/Selenium-PythonProjects/python-webui-testing

目标/目标: 解决 Geckodriver 未被检测到的问题,因此我可以通过参考来自 Automation Panda 的以下指南继续使用 Selenium 和 Pytest 在 Python 中设置自动化框架:https://blog.testproject.io/2019/07/16/read-config-files-in-python-selenium/

我已经尝试过什么?:

实际结果: 当我执行时: pipenv run python -m pytest 从以下目录:C:\Development\Selenium-Projects\Selenium-PythonProjects\python- webui-testing,我得到: PowerShell Execution of Pytest & Output

【问题讨论】:

    标签: python selenium pytest geckodriver system-paths


    【解决方案1】:

    问题不在于 geckodriver 的路径。问题是在 Python 代码中找不到“Firefox”作为标记。

    使用配置夹具将此导入添加到模块中:“from selenium.webdriver import Firefox”。

    【讨论】:

    • 你的评论让我意识到我已经评论了import firefoxxD 谢谢
    【解决方案2】:

    我建议使用 webdriver_manager,这样您就不必处理所有这些问题。这很简单,如下所示。 webdriver_manager 将获得基于操作系统和架构的最新稳定驱动程序。

    from selenium import webdriver
    from webdriver_manager.firefox import GeckoDriverManager
    
    driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
    driver.get("https://www.google.com")
    # continue using the driver as usual.
    

    【讨论】:

      猜你喜欢
      • 2019-06-10
      • 1970-01-01
      • 1970-01-01
      • 2017-06-07
      • 2018-09-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-24
      相关资源
      最近更新 更多