本文介绍了WebDriverException:消息:无效参数:无法在 RaspberryPi3 上使用 GeckoDriver、Selenium 和 Python 终止已退出的进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

服务器:树莓派 3
操作系统:Dietpi - 版本 159
Geckodriver 版本:0.22 for arm
火狐版本:52.9.0
Python 版本:3.5
硒版本:3.14.1

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

from selenium import webdriverfrom selenium.webdriver.common.by import By从 selenium.webdriver.support.ui 导入 WebDriverWait从 selenium.webdriver.support 导入 expected_conditions 作为 EC从 selenium.webdriver.firefox.options 导入选项导入时间选项 = 选项()options.set_headless(headless=True)驱动程序 = webdriver.Firefox(firefox_options=options)print('需要您的登录凭据')username = input('你的用户名是什么?:
')password = input('你的密码是什么?:
')......

输出:

root@RPi3:~# python3.5 ITE-bot.py回溯(最近一次调用最后一次):文件ITE-bot.py",第 12 行,在 <module> 中驱动程序 = webdriver.Firefox(firefox_options=options)文件/usr/local/lib/python3.5/dist-packages/selenium/webdriver/firefox/webdriver.py",第 174 行,在 __init__ 中keep_alive=真)文件/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py",第 157 行,在 __init__ 中self.start_session(功能,browser_profile)文件/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py",第 252 行,在 start_session 中response = self.execute(Command.NEW_SESSION, 参数)文件/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/webdriver.py",第321行,在执行中self.error_handler.check_response(响应)文件/usr/local/lib/python3.5/dist-packages/selenium/webdriver/remote/errorhandler.py",第242行,在check_response引发异常类(消息,屏幕,堆栈跟踪)selenium.common.exceptions.WebDriverException:消息:无效参数:无法终止已退出的进程

知道出了什么问题吗?我试过谷歌但没有运气.

解决方案

Thumb rule

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


这个错误信息...

selenium.common.exceptions.WebDriverException:消息:无效参数:无法终止已退出的进程

...表示 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 升级到

    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

    Gecko is executable, and is located in /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?:
    ')
    ...
    ...
    

    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.

    解决方案

    Thumb rule


    This error message...

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

    ...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowsing Session i.e. Firefox Browser session.

    Your main issue is the incompatibility between the version of the binaries you are using as follows:

    • Your GeckoDriver version is 0.22.0.

    • Release Notes of GeckoDriver v0.21.0 (2018-06-15) clearly mentions the following:

    • Your Firefox version is 52.9.0.

    So there is a clear mismatch between GeckoDriver v0.22.0 and the Firefox Browser v57


    Solution

    • Upgrade GeckoDriver to GeckoDriver v0.22.0 level.
    • GeckoDriver is present in the specified location.
    • GeckoDriver is having executable permission for non-root users.
    • Upgrade Firefox version to Firefox v62.0.2 levels.
    • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
    • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
    • Execute your Selenium Test as a non-root user.

    GeckoDriver, Selenium and Firefox Browser compatibility chart

    这篇关于WebDriverException:消息:无效参数:无法在 RaspberryPi3 上使用 GeckoDriver、Selenium 和 Python 终止已退出的进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 01:50