WebDriver异常:消息:无效参数:无法杀死退出的进程Selenium python



虽然我知道我的问题可能与其他问题类似,但我有一个严重的问题,我在尝试运行代码时出错了Message: invalid argument: can't kill an exited process。请注意,我在ubuntu 20上运行这个程序,它没有显示。

这是我的代码:


from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options
options = Options()
options.headless = True
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install(), options=options)

控制台错误

WebDriverException: Message: invalid argument: can't kill an exited process

这是壁虎驱动程序的日志文件:

1603574335551   geckodriver INFO    Listening on 127.0.0.1:59603
1603574336562   mozrunner::runner   INFO    Running command: "/usr/bin/firefox" "--marionette" "-foreground" "-no-remote" "-profile" "/tmp/rust_mozprofilenqjQeL"
Error: no DISPLAY environment variable specified

我也读过关于版本不兼容的文章,但似乎所有版本都兼容:

  • Firefox:82.0
  • GeckoDriver:v0.27.0
  • 硒:3.141.0

我很感激您的帮助,我该如何解决?

在搜索了几个小时并浪费了一天之后,我终于明白了你必须做以下事情:

首先,你必须在无头模式下打开网络驱动程序,但不像我上面做的那样,比如:

from selenium.webdriver.firefox.options import Options
options = Options()
options.add_argument('-headless')
driver = webdriver.Firefox(executable_path='path', options=options)

还要确保你的geckodriver在ubuntu中是可执行的,使用以下命令:

sudo chmod +x geckodriver

它应该可以解决硒、萤火虫和壁虎驱动程序的新版本的问题。

最新更新