"无法找到一组匹配的功能" - 使用Python 2.7的Selenium

时间:2018-03-18 08:17:30

标签: python selenium firefox

将Selenium 3.8.1和Python 2.7与Firefox Portable 54,64位一起使用,运行此脚本时出现以下错误消息:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary

binary_argument = FirefoxBinary(r'C:\Users\[removed]\FirefoxPortable.exe')
driver = webdriver.Firefox(firefox_binary=binary_argument)

driver.get("http://icanhazip.com")

Traceback (most recent call last):
  File "F:/cp/python-selenium3/ToyScripts/launch_portable_browser.py", line 5, in <module>
    driver = webdriver.Firefox(firefox_binary=binary_argument)
  File "C:\ProgramData\Anaconda2\envs\automation2\lib\site-packages\selenium\webdriver\firefox\webdriver.py", line 162, in __init__
    keep_alive=True)
  File "C:\ProgramData\Anaconda2\envs\automation2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 154, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "C:\ProgramData\Anaconda2\envs\automation2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 243, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "C:\ProgramData\Anaconda2\envs\automation2\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
    self.error_handler.check_response(response)
  File "C:\ProgramData\Anaconda2\envs\automation2\lib\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

在它消失之前,我确实看到了闪屏。另外值得注意的是,手动使用时浏览器工作正常。

我怀疑便携式浏览器需要切换一些设置以允许Selenium接管,但这是我所知道/怀疑的程度。

感谢您对此提供任何帮助。

2 个答案:

答案 0 :(得分:2)

通过修改DesiredCapabilities解决:

from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

binary_argument = FirefoxBinary(r'C:\Users\[removed]\FirefoxPortable.exe')

capabilities_argument = DesiredCapabilities().FIREFOX
capabilities_argument["marionette"] = False

driver = webdriver.Firefox(firefox_binary=binary_argument, capabilities=capabilities_argument)

driver.get("http://icanhazip.com")

答案 1 :(得分:1)

我能够通过从https://www.seleniumhq.org/download/安装最新的geckodriver来解决此问题 和来自https://www.mozilla.org/en-US/firefox/的最新Firefox。 下载geckodriver(32位或64位)时,请考虑您的Windows。

我希望这会有所帮助。