【问题标题】:webDriverException "selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1"webDriverException “selenium.common.exceptions.WebDriverException:消息:服务 ./webdrivers/geckodriver 意外退出。状态代码为:1”
【发布时间】:2022-01-04 08:15:21
【问题描述】:

我正在为 geckodriver 运行一个简单的基于 python 的 selenium webdriver 脚本

from selenium import webdriver
geckodriver_path = "./webdrivers/geckodriver"
driver = webdriver.Firefox(executable_path=geckodriver_path)
driver.get("https://dev.to")
driver.find_element_by_id("nav-search").send_keys("Selenium")

执行后显示警告消息和异常

/<path>/demo.py:3: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
  driver = webdriver.Firefox(executable_path=geckodriver_path)

例外是

selenium.common.exceptions.WebDriverException: Message: Service ./webdrivers/geckodriver unexpectedly exited. Status code was: 1

正在使用的环境
蟒蛇(3.9.2)
硒(4.1.0)
壁虎驱动程序(0.24.0)
火狐(87.0 64 位)

geckodriver.log 的输出

error: Found argument '--websocket-port' which wasn't expected, or isn't valid in this context

USAGE:
    geckodriver [FLAGS] [OPTIONS]

For more information try --help

【问题讨论】:

    标签: python selenium selenium-webdriver


    【解决方案1】:

    在Selenium 4 之后的版本中,推荐使用Services,仍然不知道为什么,但如果有人会发现,那就太好了。

    要解决问题,你可以试试这个:

    from selenium.webdriver.firefox.service import Service as FXService
    from selenium.webdriver import Firefox
    
    
    search_by = 'xpath'
    search_path = "//div[@id='header-search']/form/div/div/input"    
    
    driver_path = './webdrivers/geckodriver'
    driver = Firefox(service=FXService(driver_path))
    
    driver.get("https://dev.to")
    driver.find_element('xpath', div_path).send_keys("Selenium")
    

    而且,exit code 1 的原因可能与 geckodriver 版本有关,请在此处查看兼容性列表:https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

    希望这会有所帮助!

    【讨论】:

    • 它在为变量 geckodriver_path 提供绝对路径后工作,还将 geckodriver 版本更新到最新的 0.30.0
    【解决方案2】:

    它在为变量 geckodriver_path 提供绝对路径后工作,还将 geckodriver 版本更新为最新版本。 (目前是 0.30.0 兼容 firefox 87.0 64-bit )

    【讨论】:

      猜你喜欢
      • 2017-08-31
      • 2021-09-03
      • 1970-01-01
      • 1970-01-01
      • 2019-05-28
      • 1970-01-01
      • 2020-09-16
      • 2021-03-15
      • 2018-08-25
      相关资源
      最近更新 更多