OS:Ubuntu 18.04.3 LTSGeckodriver版本:0.26Firefox版本:76.0.1Python版本:3.6.9硒版本:3.141.0
我的代码:
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver_options = Options()
driver_options.headless = True
browser = webdriver.Firefox(options=driver_options)
... do stuff
首先,此安装程序在我的mac电脑上正常运行,当我将其发送到生产环境时,出现该错误。我已经尝试修复了两天。
我发现了两个可能导致此问题的主要因素:
版本匹配。正如这篇文章所说:WebDriverException: Message: invalid argument: can't kill an exited process with GeckoDriver, Selenium and Python on RaspberryPi3我检查了我的版本,它们是兼容的
Geckodriver在路径中我在代码旁边添加了一个软链接,以便能够同时找到geckodriver和firefox
geckodriver和firefox都具有777权限
如果我从终端以无头模式运行Firefox,似乎运行正常
geckodriver.log文件正在输出:
1590245018121 mozrunner::runner INFO Running command: "/var/www/mycode/env/bin/firefox" "-marionette" "-headless" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofile7raE8H"
/var/www/mycode/env/bin/firefox: 1: /var/www/mycode/env/bin/firefox: which: not found
由于我可以从终端运行脚本,所以我最终意识到他的问题是金枪鱼。我必须添加Environment="PATH=/usr/bin"
服务器上运行的gunicorn服务脚本。