【问题标题】:Selenium Error: Unable to find a matching set of capabilities [duplicate]Selenium 错误:无法找到一组匹配的功能 [重复]
【发布时间】:2020-07-18 11:40:21
【问题描述】:

这是我正在使用的代码

from selenium import webdriver

url = "https://www.reddit.com/r/memes"
browser = webdriver.Firefox()
browser.get(url)

这是错误

Traceback (most recent call last):
  File "main.py", line 4, in <module>
    browser = webdriver.Firefox()
  File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 170, in __init__
    RemoteWebDriver.__init__(
  File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/home/jiahong/python/scrapping/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

我在 Ubuntu 中使用 WSL,并且正在使用 Vim。但是,如果我不在 WSL 之外并改用 VSC,我不会收到此错误。但我想用 Vim 编写代码。

【问题讨论】:

标签: python selenium vim


【解决方案1】:

在代码中,您没有提到 geckodriver 可执行文件的路径。您的代码应如下所示:

from selenium import webdriver

url = "https://www.reddit.com/r/memes"
browser = webdriver.Firefox(f'/home/user/Downloads/geckodriver')
# Or in Windows the path would be 'C:\\Users\\username\\Downloads\\geckodriver.exe'
browser.get(url)

如果您还没有驱动程序,请从here 获取。

【讨论】:

  • 我的 geckodriver 在 ~/.local/bin 因为它是我不需要包含它的路径。错误不在于路径,而在于功能。
  • 但是你有没有尝试在你的主目录中使用 geckodriver
  • 抱歉回复晚了。但你的意思是什么?
  • 我将它添加到首页,但仍然出现相同的错误
猜你喜欢
  • 1970-01-01
  • 2018-07-30
  • 2018-08-27
  • 1970-01-01
  • 2020-04-28
  • 1970-01-01
  • 2017-11-30
  • 2019-01-30
相关资源
最近更新 更多