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

Cho*_*iks 16 python firefox selenium raspberry-pi3 geckodriver

服务器:Raspberry Pi 3
OS: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?:\n')
password = input('What is your password?:\n')
...
...
Run Code Online (Sandbox Code Playgroud)

输出:

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
Run Code Online (Sandbox Code Playgroud)

知道什么是错的吗?我试过谷歌没有运气.

NFe*_*ern 28

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

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

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Run Code Online (Sandbox Code Playgroud)

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

  • 谢谢,这在运行ubuntu 16.04的服务器上遇到类似问题时对我有用 (3认同)

Deb*_*anB 26

此错误消息...

selenium.common.exceptions.WebDriverException: Message: invalid argument: can't kill an exited process
Run Code Online (Sandbox Code Playgroud)

...暗示GeckoDriver无法启动/生成新的WebBrowsing会话,Firefox浏览器会话.

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

  • 您的GeckoDriver版本是0.22.0.
  • GeckoDriver v0.21.0(2018-06-15)的发行说明清楚地提到了以下内容:

    • Firefox 57(及更高版本)

    • 硒3.11(及以上)

  • 您的Firefox版本是52.9.0.

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

  • 升级GeckoDriverGeckoDriver v0.22.0水平.
  • GeckoDriver存在于指定位置.
  • GeckoDriver拥有非root用户的可执行权限.
  • Firefox版本升级到Firefox v62.0.2级别.
  • 清理你的项目工作,通过你的IDE重建仅需要依赖你的项目.
  • 如果您的基本Web客户端版本太旧,请通过Revo Uninstaller将其卸载并安装最新的GA和已发布的Web客户端版本.
  • __CODE__以非root用户身份执行您的操作.

  • 我将所有内容更新到最新版本,geckodriver 位于我的计算机上的正确位置(运行 ubuntu 19.04),但我仍然收到与原始问题相同的错误消息。不知道现在该怎么办 (7认同)
  • @DebanjanB 在机器人框架中,在 ubuntu 18.04 中安装了 python 3.6.9、Firefox 77.0.1 和 geckodriver 0.26.0,出现错误“WebDriverException:消息:无效参数:无法终止已退出的进程”,您能帮忙吗? (2认同)

Rog*_*lio 7

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


Mig*_*nde 6

是的,已选中在构建可以解决问题之前启动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

  • 由于以无头模式运行浏览器,因此不需要xvfb。 (2认同)
  • 这应该是最佳答案 - Firefox 不会在 X 会话之外运行,因此如果有人通过 docker 或 ssh 运行,请确保启动 Xvfb 来模拟它 (2认同)

Ana*_*nov 6

这个解决方案对我有用

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

options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
Run Code Online (Sandbox Code Playgroud)

  • 如果您收到 WebDriverException 错误,并且您拥有最新版本的 firefox 和 geckdriver,并且您使用的是无头计算机,则需要设置 headless = True,正如 Anar 在此提到的那样。 (6认同)