Selenium "Невозможно найти соответствующий набор возможностей", несмотря на то, что драйвер находится в/usr/local/bin

Я пытаюсь следовать учебнику о Selenium, http://selenium-python.readthedocs.io/getting-started.html. Я загрузил последнюю версию geckodriver и скопировал ее в /usr/local/bin. Однако, когда я пытаюсь

from selenium import webdriver
driver = webdriver.Firefox()

Появляется следующее сообщение об ошибке:

Traceback (most recent call last):
  File "/Users/kurtpeek/Documents/Scratch/selenium_getting_started.py", line 4, in <module>
    driver = webdriver.Firefox()
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 152, in __init__
    keep_alive=True)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 98, in __init__
    self.start_session(desired_capabilities, browser_profile)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 188, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities

[Finished in 1.2s with exit code 1]

Из https://github.com/SeleniumHQ/selenium/issues/3884 похоже, что другие пользователи испытывают схожие проблемы, но команда Selenium не может воспроизвести ее. Как я могу заставить Selenium работать с Firefox? (Он работает с экземплярами chromedriver и webdriver.Chrome(), поэтому я подозреваю, что это может быть ошибкой в ​​Selenium).

Ответы

Ответ 1

Обновление Firefox и Selenium решило это для меня. Однако я не претендую на объяснение первопричины.

  • Обновлен Firefox 48 → 53
  • Обновлено до Selenium 3.4.1

Я также переустанавливал/обновлял Geckodriver с помощью Homebrew и явно использовал его в качестве исполняемого файла для Selenium WebDriver, но оказалось, что нет необходимости Geckodriver "Невозможно найти соответствующий набор возможностей".

Ответ 2

В качестве примечания, убедитесь, что у вас есть правильная версия 32/64bit для вашего geckodriver.

Ответ 3

для меня было достаточно просто обновить FF

Ответ 4

Пользователь Mac здесь.

Я исправил эту проблему, убедившись, что Firefox называется "Firefox" и находится в папке "Приложения". Я назвал его "Firefox 58" раньше (у меня есть несколько версий).

Ответ 5

Просто делюсь своим примером успеха здесь

Примечание: Помните, что вопросы архитектуры здесь, Window 64/32 или Linux 64/32. Убедитесь, что вы загрузили правильный 64/32 битный Selenium Webdriver, 64/32 Geckodriver.

Моя конфигурация была следующей:

Linux: Centos 7 64bit, Window 7 64bit

Firefox: 52.0.3

Selenium Webdriver: 3.4.0 (Windows), 3.8.1 (Linux Centos)

GeckoDriver: v0.16.0 (Windows), v0.17.0 (Linux Centos)

Рабочий код (без настроек прокси)

System.setProperty("webdriver.gecko.driver", "/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver");

ProfilesIni ini = new ProfilesIni();


// Change the profile name to your own. The profile name can 
// be found under .mozilla folder ~/.mozilla/firefox/profile. 
// See you profile.ini for the default profile name

FirefoxProfile profile = ini.getProfile("default"); 

DesiredCapabilities cap = new DesiredCapabilities();
cap.setAcceptInsecureCerts(true);

FirefoxBinary firefoxBinary = new FirefoxBinary();

GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
        .usingDriverExecutable(new File("/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver"))
        .usingAnyFreePort()
        .build();
try {
    service.start();
} catch (IOException e) {
    e.printStackTrace();
}

FirefoxOptions options = new FirefoxOptions().setBinary(firefoxBinary).setProfile(profile).addCapabilities(cap);

driver = new FirefoxDriver(options);
driver.get("https://www.google.com");

System.out.println("Life Title -> " + driver.getTitle());
driver.close();

Рабочий код (с настройками прокси)

    System.setProperty("webdriver.gecko.driver", "/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver");

    String PROXY = "my-proxy.co.jp";
    int PORT = 8301;


    ProfilesIni ini = new ProfilesIni();


    // Change the profile name to your own. The profile name can 
    // be found under .mozilla folder ~/.mozilla/firefox/profile. 
    // See you profile.ini for the default profile name

    FirefoxProfile profile = ini.getProfile("default"); 


    com.google.gson.JsonObject json = new com.google.gson.JsonObject();
    json.addProperty("proxyType", "manual");
    json.addProperty("httpProxy", PROXY);
    json.addProperty("httpProxyPort", PORT);
    json.addProperty("sslProxy", PROXY);
    json.addProperty("sslProxyPort", PORT);

    DesiredCapabilities cap = new DesiredCapabilities();
    cap.setAcceptInsecureCerts(true);
    cap.setCapability("proxy", json);


    FirefoxBinary firefoxBinary = new FirefoxBinary();

    GeckoDriverService service =new GeckoDriverService.Builder(firefoxBinary)
            .usingDriverExecutable(new File("/home/seleniumproject/geckodrivers/linux/v0.17/geckodriver"))
            .usingAnyFreePort()
            .usingAnyFreePort()
            .build();
    try {
        service.start();
    } catch (IOException e) {
        e.printStackTrace();
    }

    FirefoxOptions options = new FirefoxOptions().setBinary(firefoxBinary).setProfile(profile).addCapabilities(cap);

    driver = new FirefoxDriver(options);
    driver.get("https://www.google.com");

    System.out.println("Life Title -> " + driver.getTitle());
    driver.close();

Ответ 6

В моем случае у меня только Firefox Developer Edition, но все равно выдает ту же ошибку.

После установки стандартной версии Firefox это решает.

Ответ 7

Я была такая же проблема. Мой geckodriver был 32-битным, а fireFox - 64. Решено обновлением geckodriver до 64-битного.

Ответ 8

Получил ту же ошибку на капле в DigitalOcean - FireFox не был установлен. След ошибки стека был как показано ниже -

exception_class 
<class 'selenium.common.exceptions.SessionNotCreatedException'>
json    
<module 'json' from '/usr/lib/python3.5/json/__init__.py'>
message 
'Unable to find a matching set of capabilities'
response    
{'status': 500,
 'value': '{"value":{"error":"session not created","message":"Unable to find a '
          'matching set of capabilities","stacktrace":""}}'}
screen  
None
self    
<selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x7f428e3f10f0>
stacktrace  
None
status  
'session not created'
value   
{'error': 'session not created',
 'message': 'Unable to find a matching set of capabilities',
 'stacktrace': ''}
value_json  
('{"value":{"error":"session not created","message":"Unable to find a matching '
 'set of capabilities","stacktrace":""}}')