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のバグではないかと思います)。
FirefoxとSeleniumをアップデートしたら解決しました。しかし、根本的な原因を説明するつもりはありません。
また、Homebrew
を使用して Geckodriver
を再インストール/更新し、明示的に Selenium WebDriver
の実行ファイルとして使用したが、"Unable to find matching set of capabilities" エラーを軽減するためには必要ないことが判明した。
ここで私の成功事例を共有してください。
注:ここでは、アーキテクチャの問題、ウィンドウ64/32またはLinux 64/32に注意してください。 正しい64/32ビットSelenium Webdriver、64/32 Geckodriverをダウンロードしてください。
私の構成は次のとおりです。。
Linux:Centos 7 64ビット、ウィンドウ7 64ビット
。
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();
DigitalOceanの液滴で同じエラーが発生しました-FireFoxがインストールされていません。 . エラーのスタックトレースは以下のようになりました-。
。 exception_class。 < class 'selenium.common.exceptions.SessionNotCreatedException'>。 json。 <モジュール 'json' from '/usr/lib/python3.5/json/__init__.py'> メッセージ。 「一致する機能のセットを見つけることができません」。 応答。 {'status':500、。 'value': '{"value":{"error": "session not created"、 "message": "a 'を見つけることができません。 「一致する機能のセット」、「stacktrace」:「 "}}'}。 画面。 無し。 自己。 < selenium.webdriver.remote.errorhandler.ErrorHandlerオブジェクト、0x7f428e3f10f0> stacktrace。 無し。 ステータス。 「セッションが作成されていません」。 値。 {'error': 'session not created'、。 'メッセージ': '一致する機能のセットを見つけることができません'、。 'stacktrace': ''}。 value_json。 ( '{"value":{"error": "session not created"、 "message": "一致するものが見つかりません'。 'set of facilitys"、 "stacktrace": ""}} ')。
。