为什么 selenium 不能与 Firefox 一起使用,但在重新安装后却可以无缝运行?

Why can't selenium work with Firefox but it works seamlessly after re-installation?

所以我从 'Automate the boring stuff with Python' 开始,现在正在学习第 11 章,即网络抓取。 在此期间,我努力让我的 selenium 与 Firefox 一起工作。版本详情如下:

Windows 10 Pro (64 bit)
Firefox: 81.0 (64 bit) (Latest at the time of writing)
Python: 3.7.9
Selenium: 3.141.0
Geckodriver: 0.27

当我 运行 以下脚本时,它崩溃并出现异常:

from selenium import webdriver
driver = webdriver.Firefox()
driver.get("http://www.python.org")

异常:

Unable to find a matching set of capabilities

我下载了火狐安装器(使用火狐浏览器),重新安装,还是一样的版本,问题神奇地消失了。 我的问题更多是关于问题的原因,这对我来说仍然是未知的。什么可能导致脚本第一次崩溃,因为实际上我没有改变任何东西。

2个猜测:

  1. 您在重新安装之前使用的是较低版本的 Firefox
  2. 可能是因为与您 OS 中设置的默认浏览器发生冲突,以避免您可以显式指定 Firefox 二进制文件的路径:
driver = webdriver.Firefox(
  executable_path='/path/to/geckodriver', 
  firefox_binary='/path/to/firefox/binary'
)