【问题标题】:Seleium and Geckodriver not working python [duplicate]Selenium 和 Geckodriver 不工作 python [重复]
【发布时间】:2019-12-16 19:43:51
【问题描述】:

我正在尝试在 python 中使用 selenium 编写一个程序,该程序将打开一个 firefox 窗口并转到 twitter。我已将 geckdriver.exe 放在我的 python 3.6 文件夹中并安装了 firefox。我还运行了“pip install selnium”并安装了 selenium。

这是我写的代码:

from selenium import webdriver

browser = webdriver.Firefox(executable_path="C:\\Users\\Harry\\AppData\\Local\\Programs\\Python\\Python36-32\\geckodriver.exe")
browser.get("https://www.twitter.com/")`

运行时输出为:

PS C:\Users\Harry\Desktop\Coding\Python\Bots\TwitterBot> python app.py 回溯(最近一次通话最后): 文件“app.py”,第 5 行,在 浏览器 = webdriver.Firefox() init 中的文件“C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\firefox\webdriver.py”,第 174 行 keep_alive=真) init 中的文件“C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 157 行 self.start_session(功能,浏览器配置文件) 文件“C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 252 行,在 start_session 响应 = self.execute(Command.NEW_SESSION,参数) 文件“C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py”,第 321 行,在执行 self.error_handler.check_response(响应) 文件“C:\Users\Harry\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py”,第 242 行,在 check_response 引发异常类(消息、屏幕、堆栈跟踪) selenium.common.exceptions.SessionNotCreatedException:消息:无法找到匹配的功能集

为什么会这样,我能做些什么来解决它? 我正在使用 python 3.6 和 Visual Studio Code 来编写我的程序。 Firefox 版本在撰写本文时是最新版本。

【问题讨论】:

标签: python selenium firefox


【解决方案1】:

我认为您必须尝试以下解决方案之一:

  • 使用 DesiredCapabilities:

    from Selenium import webdriver
    
    from Selenium.webdriver.common.desired_capabilities import DesiredCapabilities
    
    cap = DesiredCapabilities().FIREFOX
    
    cap["marionette"] = False
    
    browser = webdriver.Firefox(capabilities=cap, executable_path="C:\\Users\\Harry\\AppData\\Local\\Programs\\Python\\Python36-32\\geckodriver.exe")
    
    browser.get('https://twitter.com/')
    
    browser.quit()
    
  • 更新 Firefox 和 Selenium 并重新安装 geckodriver

【讨论】:

    猜你喜欢
    • 2018-05-29
    • 1970-01-01
    • 1970-01-01
    • 2019-06-01
    • 2018-01-11
    • 1970-01-01
    • 2012-01-02
    • 2018-05-30
    • 2018-10-16
    相关资源
    最近更新 更多