WebDriverException:消息:无效参数:无法使用 RaspberryPi3 上的 GeckoDriver、Selenium 和 Python 终止已退出的进程

2025-01-16 08:37:00
admin
原创
80
摘要:问题描述:服务器:Raspberry Pi 3 操作系统:Dietpi - 版本 159 Geckodriver 版本:0.22 for arm Firefox 版本:52.9.0 Python 版本:3.5 Selenium 版本:3.14.1 Gecko 是可执行文件,位于 /usr/l...

问题描述:

服务器:Raspberry Pi 3

操作系统:Dietpi - 版本 159

Geckodriver 版本:0.22 for arm

Firefox 版本:52.9.0

Python 版本:3.5

Selenium 版本:3.14.1

Gecko 是可执行文件,位于 /usr/local/bin/

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.options import Options
import time



options = Options()
options.set_headless(headless=True)
driver = webdriver.Firefox(firefox_options=options)

print('Need your login credential')
username = input('What is your username?:
')
password = input('What is your password?:
')
...
...

输出:

root@RPi3:~# python3.5 ITE-bot.py 
Traceback (most recent call last):
  File "ITE-bot.py", line 12, in <module>
    driver = webdriver.Firefox(firefox_options=options)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py", line 174, in __init__
    keep_alive=True)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

知道哪里出了问题吗?我试过谷歌搜索,但没有成功。


解决方案 1:

如果您在没有显示屏的系统上运行 Firefox,请确保使用无头模式。

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

另外,请确保您拥有兼容版本的 Firefox、Selenium 和 Geckodriver:
https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html

解决方案 2:

经验法则

root浏览器在启动过程中崩溃的一个常见原因是在 Linux 上以用户 ( )身份运行 WebDriver 启动的浏览器administrator。虽然可以--no-sandbox在创建 WebDriver 会话时传递标志来解决此问题,但这种配置不受支持且极不鼓励。您需要将环境配置为以普通用户身份运行浏览器。


此错误信息...

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process

...意味着GeckoDriver无法启动/产生新的WebBrowsing 会话,即Firefox 浏览器会话。

您的主要问题是您使用的二进制文件版本不兼容,如下所示:

  • 您的GeckoDriver版本是0.22.0

  • GeckoDriver v0.21.0(2018-06-15)的发行说明明确提到以下内容:

  • Firefox 57(及更高版本)

  • Selenium 3.11(及更高版本)

  • 您的Firefox版本是52.9.0

因此, GeckoDriver v0.22.0Firefox Browser v57之间存在明显不匹配


解决方案

  • 将GeckoDriver升级到GeckoDriver v0.22.0级别。

  • GeckoDriver 位于指定位置。

  • GeckoDriver 对非root用户具有可执行权限。

  • 升级Firefox版本至Firefox v62.0.2级别。

  • 通过IDE清理项目工作区,然后仅使用所需的依赖项重建项目。

  • 如果您的基本Web Client版本太旧,请通过Revo Uninstaller将其卸载并安装最新的 GA 和发布版本的Web Client

  • 非 root 用户身份执行Selenium 测试


GeckoDriverSeleniumFirefox 浏览器兼容性图表

geckodriver_versions

解决方案 3:

我处于无头模式,使用所有内容的正确版本,摆脱此错误消息的唯一方法是以 root 身份执行 selenium 测试

解决方案 4:

是的,选中“在构建之前启动 Xvfb”可以解决问题,但如果您有像管道或多分支管道这样的作业,则此选项不可见。在您执行测试的 Selenium 网格节点中,您需要:

1-安装Xvfb:apt install xvfb

2-执行Xvfb:/usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"

3-重新运行你的节点,例如:java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991

解决方案 5:

这个解决方案对我有用

from selenium import webdriver
from selenium.webdriver.firefox.options import Options

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)

解决方案 6:

由于此错误可能有许多不同的潜在原因,因此最好找到根本原因,将 selenium 设置为使用调试级别日志记录。 在我的例子中,对于带有 capybara 的 Ruby,我需要设置:Selenium::WebDriver.logger.level = :debug。 然后,运行相同的规范,我可以在日志中看到缺少依赖项,在我的例子中:

libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.

安装后一切运行正常。

解决方案 7:

我用过:

  • VS 代码

  • Linux/Ubuntu:18.10

  • Nightwatch.js

我的问题是我尝试VS Code 终端运行 Nightwatch(它会自动启动 GeckoDriver)。

解决方案 8:

我遇到了同样的问题,并意识到真正的问题是我正在测试的docker容器内没有安装一些firefox依赖项。

尝试启动firefox并检查它是否返回错误。

解决方案 9:

正如 Nico 和 jay 所说,您需要检查日志以查看错误的详细信息。由于您可能使用不同的系统,因此您可以指定存储日志的路径(即“/tmp/geckodriver.log”)。

from selenium import webdriver
firefox_options = webdriver.firefox.webdriver.Options()
driver = webdriver.Firefox(log_path="/tmp/geckodriver.log", 
                           options=firefox_options)

就我的情况而言,日志内容如下:

Error: no DISPLAY environment variable specified

通过在启动驱动程序之前在选项中添加无头模式解决了这个问题。使用以下行:

firefox_options.set_headless()

解决方案 10:

我能够通过使用 Xvfb 运行测试来解决这个问题。我在远程服务器上运行它们。

我使用的是 Jenkins,因此我选中了如下复选框:

来源:https://www.obeythetestinggoat.com/book/chapter_CI.html

来源:https://www.obeythetestinggoat.com/book/chapter_CI.html

解决方案 11:

就我而言,我以 root 身份运行测试用例

geckodriver.log

1576076416677   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenCbl2e"
Running Firefox as root in a regular user's session is not supported.  ($HOME is /home/seluser which is owned by seluser.)
1576077143004   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7wpSQ7"
1576077143689   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: mozillaAddons
1576077143689   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: telemetry
1576077143689   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: resource://pdf.js/
1576077143689   addons.webextension.screenshots@mozilla.org     WARN    Loading extension 'screenshots@mozilla.org': Reading manifest: Invalid extension permission: about:reader*
1576077145372   Marionette      INFO    Listening on port 35571
1576077145423   Marionette      WARN    TLS certificate errors will be ignored for this session
1576077200207   mozrunner::runner       INFO    Running command: "/usr/bin/firefox" "-marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenhoHlr"
Running Firefox as root in a regular user's session is not supported.  ($HOME is /home/seluser which is owned by seluser.)

我可以绕过

cd /home
chown -R  root seluser

我不能说它正确但它完成了我的工作

相关推荐
  政府信创国产化的10大政策解读一、信创国产化的背景与意义信创国产化,即信息技术应用创新国产化,是当前中国信息技术领域的一个重要发展方向。其核心在于通过自主研发和创新,实现信息技术应用的自主可控,减少对外部技术的依赖,并规避潜在的技术制裁和风险。随着全球信息技术竞争的加剧,以及某些国家对中国在科技领域的打压,信创国产化显...
工程项目管理   1565  
  为什么项目管理通常仍然耗时且低效?您是否还在反复更新电子表格、淹没在便利贴中并参加每周更新会议?这确实是耗费时间和精力。借助软件工具的帮助,您可以一目了然地全面了解您的项目。如今,国内外有足够多优秀的项目管理软件可以帮助您掌控每个项目。什么是项目管理软件?项目管理软件是广泛行业用于项目规划、资源分配和调度的软件。它使项...
项目管理软件   1354  
  信创国产芯片作为信息技术创新的核心领域,对于推动国家自主可控生态建设具有至关重要的意义。在全球科技竞争日益激烈的背景下,实现信息技术的自主可控,摆脱对国外技术的依赖,已成为保障国家信息安全和产业可持续发展的关键。国产芯片作为信创产业的基石,其发展水平直接影响着整个信创生态的构建与完善。通过不断提升国产芯片的技术实力、产...
国产信创系统   21  
  信创生态建设旨在实现信息技术领域的自主创新和安全可控,涵盖了从硬件到软件的全产业链。随着数字化转型的加速,信创生态建设的重要性日益凸显,它不仅关乎国家的信息安全,更是推动产业升级和经济高质量发展的关键力量。然而,在推进信创生态建设的过程中,面临着诸多复杂且严峻的挑战,需要深入剖析并寻找切实可行的解决方案。技术创新难题技...
信创操作系统   27  
  信创产业作为国家信息技术创新发展的重要领域,对于保障国家信息安全、推动产业升级具有关键意义。而国产芯片作为信创产业的核心基石,其研发进展备受关注。在信创国产芯片的研发征程中,面临着诸多复杂且艰巨的难点,这些难点犹如一道道关卡,阻碍着国产芯片的快速发展。然而,科研人员和相关企业并未退缩,积极探索并提出了一系列切实可行的解...
国产化替代产品目录   28  
热门文章
项目管理软件有哪些?
云禅道AD
禅道项目管理软件

云端的项目管理软件

尊享禅道项目软件收费版功能

无需维护,随时随地协同办公

内置subversion和git源码管理

每天备份,随时转为私有部署

免费试用