WebDriverException:消息:无效参数:无法在 RaspberryPi3 上使用 GeckoDriver、Selenium 和 Python 杀死已退出的进程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52534658/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3
提问by Chokoladekiks
Server: Raspberry Pi 3
OS: Dietpi - version 159
Geckodriver version: 0.22 for arm
Firefox version: 52.9.0
Python version: 3.5
Selenium version: 3.14.1
服务器:Raspberry Pi 3
操作系统:Dietpi - 版本 159
Geckodriver 版本:0.22 for arm
Firefox 版本:52.9.0
Python 版本:3.5
Selenium 版本:3.14.1
Gecko is executable, and is located in /usr/local/bin/
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')
...
...
Output:
输出:
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
Any idea what is wrong? I've tried google without luck.
知道出了什么问题吗?我试过谷歌没有运气。
回答by NFern
If you are running Firefox on a system with no display, make sure you use headless mode.
如果您在没有显示器的系统上运行 Firefox,请确保使用无头模式。
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Also, make sure you have compatible versions of Firefox, Selenium, and Geckodriver: https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html
另外,请确保您拥有兼容版本的 Firefox、Selenium 和 Geckodriver:https://firefox-source-docs.mozilla.org/testing/geckodriver/Support.html
回答by DebanjanB
This error message...
这个错误信息...
selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
...implies that the GeckoDriverwas unable to initiate/spawn a new WebBrowsing Sessioni.e. Firefox Browsersession.
...暗示GeckoDriver无法启动/生成新的WebBrowsing 会话,即Firefox 浏览器会话。
Your main issue is the incompatibilitybetween the version of the binaries you are using as follows:
您的主要问题是您使用的二进制文件版本之间的不兼容,如下所示:
- Your GeckoDriverversion is 0.22.0.
Release Notes of GeckoDriver v0.21.0 (2018-06-15)clearly mentions the following:
Firefox 57 (and greater)
Selenium 3.11 (and greater)
Your Firefoxversion is 52.9.0.
- 您的GeckoDriver版本是0.22.0。
GeckoDriver v0.21.0 (2018-06-15) 的发行说明清楚地提到了以下内容:
Firefox 57(及更高版本)
Selenium 3.11(及更高版本)
您的Firefox版本是52.9.0。
So there is a clear mismatch between GeckoDriver v0.22.0and the Firefox Browser v57
所以GeckoDriver v0.22.0和Firefox Browser v57之间存在明显的不匹配
Solution
解决方案
- Upgrade GeckoDriverto GeckoDriver v0.22.0level.
- GeckoDriver is present in the specified location.
- GeckoDriver is having executable permission for non-rootusers.
- Upgrade Firefoxversion to Firefox v62.0.2levels.
- Cleanyour Project Workspacethrough your IDEand Rebuildyour project with required dependencies only.
- If your base Web Clientversion is too old, then uninstall it through Revo Uninstallerand install a recent GA and released version of Web Client.
- Execute your Selenium Testas a non-root user.
- 升级GeckoDriver到GeckoDriver v0.22.0水平。
- GeckoDriver 存在于指定位置。
- GeckoDriver 对非 root用户具有可执行权限。
- 将Firefox版本升级到Firefox v62.0.2级别。
- 清理你的项目工作,通过你的IDE和重建仅需要依赖你的项目。
- 如果您的基本Web Client版本太旧,请通过Revo Uninstaller卸载它并安装最新的 GA 和发布版本的Web Client。
- 以非 root 用户身份执行您的Selenium 测试。
GeckoDriver, Seleniumand Firefox Browsercompatibility chart
GeckoDriver、Selenium和Firefox 浏览器兼容性图表
回答by Rogelio
I was on headless mode, using correct versions of everything, and the only way to get out of this error message was notto execute the selenium test as root
我处于无头模式,使用正确版本的所有内容,摆脱此错误消息的唯一方法是不要以 root 身份执行 selenium 测试
回答by conde
Yes checked Start Xvfb before the build can fix the problem, but if you have a job like a pipeline or multibranch pipeline this option is not visible. In the node of your Selenium grid that you go to execute the test you need:
是在构建可以解决问题之前选中 Start Xvfb,但如果您有像管道或多分支管道这样的工作,则此选项不可见。在您要执行测试的 Selenium 网格节点中:
1- Install Xvfb: apt install xvfb
1- 安装 Xvfb: apt install xvfb
2- Execute Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
2- 执行 Xvfb: /usr/bin/Xvfb :99 -ac -screen 0 1024x768x8 & export DISPLAY=":99"
3- Rerun your node, for example: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991
3- 重新运行您的节点,例如: java -jar selenium.jar -role node -hub http://#.#.#.#:4444/grid/register -capabilities browserName=firefox,plataform=linux -host #.#.#.# -port 1991
回答by Anar Salimkhanov
This solution worked for me
这个解决方案对我有用
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
回答by flow3r
I used:
我用了:
- VS Code
- Linunx/Ubuntu:18.10
- Nightwatch.js
- VS代码
- Linux/Ubuntu:18.10
- 守夜人.js
My problem was that I tried to run Nightwatch (which automatically starts GeckoDriver) fromthe VS Code terminal.
我的问题是我试图从VS Code 终端运行 Nightwatch(它会自动启动 GeckoDriver)。
回答by Jeff
With geckodriver 26.0, and firefox 70.0.1 I am getting the same error, when I run it in VS code on Windows under WSL: Ubuntu.
使用 geckodriver 26.0 和 firefox 70.0.1,当我在 WSL: Ubuntu 下的 Windows 上的 VS 代码中运行它时,我遇到了同样的错误。
Headless is set to True.
Headless 设置为 True。
I tried running it as sudo in the bash terminal within VS code. I got the same error.
我尝试在 VS 代码中的 bash 终端中将它作为 sudo 运行。我得到了同样的错误。
Running it outside of VS code, as sudo and not, I also get the same error.
在 VS 代码之外运行它,作为 sudo 而不是,我也得到同样的错误。
回答by Carmon
I had the same problem, and realized that the real problem was some firefox dependencies not being installed inside the docker container I was testing in.
我遇到了同样的问题,并意识到真正的问题是我正在测试的 docker 容器中没有安装一些 Firefox 依赖项。
Try to initiate firefox
and check if it returns an error.
尝试启动firefox
并检查它是否返回错误。
回答by Daniel Butler
I was able to fix this by running my tests with Xvfb. I was running them on a remote server.
我能够通过使用 Xvfb 运行我的测试来解决这个问题。我在远程服务器上运行它们。
I was using Jenkins so I checked the box that looked like this:
我正在使用 Jenkins,所以我检查了如下所示的框:
Credit to https://www.obeythetestinggoat.com/book/chapter_CI.html
回答by jay fegade
in my case, I was running test cases as root
就我而言,我以 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 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
1576077143689 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: telemetry
1576077143689 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
1576077143689 [email protected] WARN Loading extension '[email protected]': 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.)
i could get around by
我可以绕过
cd /home
chown -R root seluser
i woundnt say its correct but it got my job done
我没有说它是正确的,但它完成了我的工作