WebDriverException:消息:无效参数:can';t在RaspberryPi3上使用GeckoDriver、Selenium和Python杀死已退出的进程

WebDriverException:消息:无效参数:can';t在RaspberryPi3上使用GeckoDriver、Selenium和Python杀死已退出的进程,python,selenium,firefox,raspberry-pi3,geckodriver,Python,Selenium,Firefox,Raspberry Pi3,Geckodriver,服务器:树莓皮3 OS:Dietpi-版本159 Geckodriver版本:0.22用于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 WebDri

服务器:树莓皮3
OS:Dietpi-版本159
Geckodriver版本:0.22用于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?:\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
root@RPi3:~#python3.5 ITE-bot.py
回溯(最近一次呼叫最后一次):
文件“ITE bot.py”,第12行,在
driver=webdriver.Firefox(Firefox\u options=options)
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py”,第174行,在__
使_保持活动状态=真)
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py”,第157行,在__
启动会话(功能、浏览器配置文件)
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py”,第252行,在启动会话中
响应=self.execute(Command.NEW_会话,参数)
文件“/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py”,执行中第321行
self.error\u handler.check\u响应(响应)
文件“/usr/local/lib/python3.5/dist packages/selenium/webdriver/remote/errorhandler.py”,第242行,在check_响应中
引发异常类(消息、屏幕、堆栈跟踪)
selenium.common.exceptions.WebDriverException:消息:无效参数:无法终止已退出的进程
你知道怎么了吗?我试过谷歌,但运气不好。

拇指法则 启动期间浏览器崩溃的一个常见原因是在Linux上以root用户(
)身份运行WebDriver启动的浏览器。虽然可以通过在创建WebDriver会话时传递
--no sandbox
标志来解决此问题,但这样的配置不受支持,并且非常不推荐。您需要将环境配置为以普通用户身份运行浏览器


此错误消息

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
…意味着GeckoDriver无法启动/生成新的网络浏览会话,即Firefox浏览器会话

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

  • 您的GeckoDriver版本是0.22.0

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

  • Firefox 57(及更高版本)

  • 硒3.11(及以上)

  • 您的Firefox版本是52.9.0

因此GeckoDriver v0.22.0和Firefox浏览器v57之间存在明显的不匹配


解决方案
  • 将GeckoDriver升级至标高
  • GeckoDriver位于指定位置
  • GeckoDriver对非root用户具有可执行权限
  • 将Firefox版本升级到Firefox v62.0.2级别
  • 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
  • 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
  • 以非root用户身份执行Selenium测试


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

我使用的是Jenkins,所以我选中了如下框:


归功于

是选中在生成之前启动Xvfb可以解决问题,但是如果您有管道或多分支管道之类的作业,则此选项不可见。在Selenium网格的节点中,执行所需的测试:

1-安装Xvfb:
apt安装Xvfb

2-执行Xvfb:
/usr/bin/Xvfb:99-ac-屏幕0 1024x768x8&导出显示=“:99”


3-重新运行您的节点,例如:
java-jar selenium.jar-role-node-hub http://

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

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
此外,请确保您拥有Firefox、Selenium和Geckodriver的兼容版本:

我使用的是无头模式,使用的是所有内容的正确版本,摆脱此错误消息的唯一方法是而不是执行selenium测试,因为我使用的根目录是:

  • VS代码
  • Linunx/Ubuntu:18.10
  • Nightwatch.js

我的问题是,我试图从VS代码终端运行Nightwatch(自动启动GeckoDriver)

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,并检查它是否返回错误。

这个解决方案适合我

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

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

由于此错误可能有许多不同的根本原因,因此最好找到根本原因设置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.

安装后,一切正常。

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

从selenium导入webdriver
firefox\u options=webdriver.firefox.webdriver.options()
driver=webdriver.Firefox(log_path=“/tmp/geckodriver.log”,