WebDriverException:消息:参数无效:无法在 RaspberryPi3 上使用 GeckoDriver、Selenium 和 Python 终止退出的进程
WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3
服务器:Raspberry Pi3
OS:Dietpi - 版本 159
Geckodriver 版本:0.22 for arm
Firefox 版本:52.9.0
Python版本:3.5
硒版本: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?:\n')
password = input('What is your password?:\n')
...
...
输出:
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
知道哪里出了问题吗?我试过 google 没有运气。
拇指法则
A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as root
user (administrator
) on Linux. While it is possible to work around this issue by passing --no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...意味着 GeckoDriver 无法 initiate/spawn 新的 WebBrowsing Session 即 Firefox 浏览器 会话。
您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
您的 GeckoDriver 版本是 0.22.0.
GeckoDriver v0.21.0 (2018-06-15) 的发行说明明确提到以下内容:
-
Firefox 57 (and greater)
-
Selenium 3.11 (and greater)
您的 Firefox 版本是 52.9.0.
所以 GeckoDriver v0.22.0 和 Firefox 浏览器 v57
之间存在明显的不匹配
解决方案
- 将 GeckoDriver 升级到 GeckoDriver v0.22.0 级别。
- GeckoDriver 存在于指定位置。
- GeckoDriver 拥有 非 root 用户的可执行权限。
- 将 Firefox 版本升级到 Firefox v62.0.2 级别。
- 通过 IDE 和 [=43] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- 如果您的基础 Web Client 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web Client .
- 以 非根用户.
执行您的 Selenium 测试
GeckoDriver, Selenium and Firefox Browser compatibility chart
我能够通过 运行 我对 Xvfb 的测试来解决这个问题。我在远程服务器上 运行 他们。
我使用的是 Jenkins,所以我选中了如下所示的复选框:
是的,在构建之前检查 Start 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
如果您在没有显示的系统上使用 运行 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
我在无头模式下,使用所有的正确版本,摆脱这个错误消息的唯一方法是不以root身份执行selenium测试
我用过:
- VS 代码
- Linunx/Ubuntu:18.10
- Nightwatch.js
我的问题是我试图 运行 Nightwatch(自动启动 GeckoDriver)从 VS Code 终端。
在我的例子中,我是 运行 测试用例作为 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
我不会说它是正确的,但它完成了我的工作
我遇到了同样的问题,并意识到真正的问题是一些 firefox 依赖项没有安装在我正在测试的 docker 容器中。
尝试启动 firefox
并检查它是否 returns 错误。
这个解决方案对我有用
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
由于此错误可能有许多不同的根本原因,因此最好找到根本原因设置 selenium 以使用调试级别日志记录。在我的例子中,对于 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.
安装后一切正常。
正如 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()
服务器:Raspberry Pi3
OS:Dietpi - 版本 159
Geckodriver 版本:0.22 for arm
Firefox 版本:52.9.0
Python版本:3.5
硒版本: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?:\n')
password = input('What is your password?:\n')
...
...
输出:
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
知道哪里出了问题吗?我试过 google 没有运气。
拇指法则
A common cause for Browsers to crash during startup is running WebDriver initiated Browsers as
root
user (administrator
) on Linux. While it is possible to work around this issue by passing--no-sandbox
flag when creating your WebDriver session, such a configuration is unsupported and highly discouraged. You need to configure your environment to run Browser as a regular user instead.
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...意味着 GeckoDriver 无法 initiate/spawn 新的 WebBrowsing Session 即 Firefox 浏览器 会话。
您的主要问题是您使用的二进制文件版本之间不兼容,如下所示:
您的 GeckoDriver 版本是 0.22.0.
GeckoDriver v0.21.0 (2018-06-15) 的发行说明明确提到以下内容:
-
Firefox 57 (and greater)
-
Selenium 3.11 (and greater)
您的 Firefox 版本是 52.9.0.
所以 GeckoDriver v0.22.0 和 Firefox 浏览器 v57
之间存在明显的不匹配解决方案
- 将 GeckoDriver 升级到 GeckoDriver v0.22.0 级别。
- GeckoDriver 存在于指定位置。
- GeckoDriver 拥有 非 root 用户的可执行权限。
- 将 Firefox 版本升级到 Firefox v62.0.2 级别。
- 通过 IDE 和 [=43] 清理 您的 项目工作区 =]重建你的项目只需要依赖。
- 如果您的基础 Web Client 版本太旧,则通过 Revo Uninstaller 卸载它并安装最新的 GA 和发布版本的 Web Client .
- 以 非根用户. 执行您的 Selenium 测试
GeckoDriver, Selenium and Firefox Browser compatibility chart
我能够通过 运行 我对 Xvfb 的测试来解决这个问题。我在远程服务器上 运行 他们。
我使用的是 Jenkins,所以我选中了如下所示的复选框:
是的,在构建之前检查 Start 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
如果您在没有显示的系统上使用 运行 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
我在无头模式下,使用所有的正确版本,摆脱这个错误消息的唯一方法是不以root身份执行selenium测试
我用过:
- VS 代码
- Linunx/Ubuntu:18.10
- Nightwatch.js
我的问题是我试图 运行 Nightwatch(自动启动 GeckoDriver)从 VS Code 终端。
在我的例子中,我是 运行 测试用例作为 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
我不会说它是正确的,但它完成了我的工作
我遇到了同样的问题,并意识到真正的问题是一些 firefox 依赖项没有安装在我正在测试的 docker 容器中。
尝试启动 firefox
并检查它是否 returns 错误。
这个解决方案对我有用
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
由于此错误可能有许多不同的根本原因,因此最好找到根本原因设置 selenium 以使用调试级别日志记录。在我的例子中,对于 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.
安装后一切正常。
正如 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()