Windows10下Python+Selenium+Firefox报错:无法匹配功能集
Hey there, let's work through this "Unable to find a matching set of capabilities" error you're hitting. This is almost always a version compatibility or configuration issue with your Firefox, GeckoDriver, and Selenium setup. Here's how to troubleshoot it step by step:
1. Double-check GeckoDriver Path Configuration
First, make sure your system can find the GeckoDriver executable. Either:
- Add the folder containing
geckodriver.exeto your Windows PATH environment variable, or - Explicitly specify the path in your code like this:
from selenium import webdriver # Replace the paths with your actual file locations browser = webdriver.Firefox(executable_path=r'C:\Users\YourName\Downloads\geckodriver.exe') browser.get('http://seleniumhq.org/')
If Firefox isn't installed in the default location, you'll also need to specify its binary path:
from selenium import webdriver from selenium.webdriver.firefox.options import Options options = Options() options.binary_location = r'C:\Program Files\Mozilla Firefox\firefox.exe' browser = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe', options=options) browser.get('http://seleniumhq.org/')
2. Verify Version Compatibility
While GeckoDriver 0.20.0 is technically supposed to support Firefox 55-59, older Selenium versions sometimes have quirks with these combinations. Try upgrading your Selenium to a more stable older version that pairs well with this stack:
pip install selenium==3.141.0
Also, double-check that Firefox hasn't auto-updated to a newer version (this happens sometimes without notice!). Open Firefox, go to Help > About Firefox to confirm it's still on v59.
3. Rule Out Windows 10 Permission Issues
Windows 10's UAC (User Account Control) can sometimes block GeckoDriver from launching Firefox. Try right-clicking your Python script file and selecting Run as administrator to see if the error goes away.
4. Manually Specify Desired Capabilities
If the above steps don't work, explicitly set the capabilities to match your Firefox version:
from selenium import webdriver from selenium.webdriver.common.desired_capabilities import DesiredCapabilities caps = DesiredCapabilities.FIREFOX.copy() caps["marionette"] = True # Required for Firefox 59+ with GeckoDriver caps["acceptInsecureCerts"] = True browser = webdriver.Firefox(capabilities=caps) browser.get('http://seleniumhq.org/')
Give these steps a try—one of them should get your Selenium script up and running with Firefox 59.
内容的提问来源于stack exchange,提问作者Michael Innes

