WebDriverException:消息:无效参数:can';t在RaspberryPi3上使用GeckoDriver、Selenium和Python杀死已退出的进程
服务器:树莓皮3WebDriverException:消息:无效参数: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
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升级至标高
- GeckoDriver位于指定位置
- GeckoDriver对非root用户具有可执行权限
- 将Firefox版本升级到Firefox v62.0.2级别
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
- 以非root用户身份执行Selenium测试
拇指尺 启动期间浏览器崩溃的一个常见原因是在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升级至标高
- GeckoDriver位于指定位置
- GeckoDriver对非root用户具有可执行权限
- 将Firefox版本升级到Firefox v62.0.2级别
- 通过IDE清理项目工作区,并仅使用所需的依赖项重建项目
- 如果您的基本Web客户端版本太旧,请通过卸载它并安装最新的GA和Web客户端发布版本
- 以非root用户身份执行Selenium测试
我可以通过使用Xvfb运行测试来解决这个问题。我在远程服务器上运行它们 我使用的是Jenkins,所以我选中了如下框:
要归功于我能够通过使用Xvfb运行测试来解决这个问题。我在远程服务器上运行它们 我使用的是Jenkins,所以我选中了如下框:
归功于是选中在生成之前启动Xvfb可以解决问题,但是如果您有管道或多分支管道之类的作业,则此选项不可见。在Selenium网格的节点中,执行所需的测试: 1-安装Xvfb:
apt安装Xvfb
2-执行Xvfb:/usr/bin/Xvfb
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
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(options=options)
libdbus-glib-1.so.2: cannot open shared object file: No such file or directory
Couldn't load XPCOM.