Python 尽管驱动程序位于 /usr/local/bin 中,但 Selenium “无法找到一组匹配的功能”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/43713445/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Selenium "Unable to find a matching set of capabilities" despite driver being in /usr/local/bin
提问by Kurt Peek
I'm trying to follow a tutorial about Selenium, http://selenium-python.readthedocs.io/getting-started.html. I've downloaded the latest version of geckodriver
and copied it to /usr/local/bin
. However, when I try
我正在尝试学习有关 Selenium 的教程,http://selenium-python.readthedocs.io/getting-started.html。我已经下载了最新版本geckodriver
并将其复制到/usr/local/bin
. 但是,当我尝试
from selenium import webdriver
driver = webdriver.Firefox()
I get the following error message:
我收到以下错误消息:
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]
From https://github.com/SeleniumHQ/selenium/issues/3884, it seems like other users are experiencing similar issues, but the Selenium team is unable to reproduce it. How can I get Selenium working with Firefox? (It does work with chromedriver
and a webdriver.Chrome()
instance, so I suspect this might be a bug in Selenium).
从https://github.com/SeleniumHQ/selenium/issues/3884来看,其他用户似乎也遇到了类似的问题,但 Selenium 团队无法重现。如何让 Selenium 与 Firefox 一起工作?(它确实适用于chromedriver
一个webdriver.Chrome()
实例,所以我怀疑这可能是 Selenium 中的一个错误)。
采纳答案by Winterflags
Updating Firefox and Selenium solved it for me. I don't pretend to have an explanation for the root cause however.
更新 Firefox 和 Selenium 为我解决了这个问题。然而,我不会假装对根本原因有解释。
- Updated Firefox 48 → 53
- Updated to Selenium 3.4.1
- 更新 Firefox 48 → 53
- 更新到 Selenium 3.4.1
I also reinstalled/updated Geckodriver
using Homebrew
and explicitly used it as an executable for Selenium WebDriver
, but it turned out that it wasn't necessary to mitigate the "Unable to find matching set of capabilities"error.
我还Geckodriver
使用Homebrew
并明确将其用作 Selenium 的可执行文件重新安装/更新WebDriver
,但结果证明没有必要减轻“无法找到匹配的功能集”错误。
回答by elad silver
for me it was enough to just upgrade FF
对我来说,升级FF就足够了
回答by Jeremy S.
Mac user here.
Mac 用户在这里。
I fixed this issue by making sure Firefox is named "Firefox" and in the "Applications" folder. I had called it "Firefox 58" before (I have multiple versions).
我通过确保 Firefox 被命名为“Firefox”并在“应用程序”文件夹中解决了这个问题。我之前称它为“Firefox 58”(我有多个版本)。
回答by HA S
Just sharing my success case here
在这里分享我的成功案例
Note: Remember the Architecture matters here, Window 64/32 or Linux 64/32. Make sure you download the right 64/32 bit Selenium Webdriver, 64/32 Geckodriver.
注意:请记住这里的架构很重要,Window 64/32 或 Linux 64/32。确保下载正确的 64/32 位 Selenium Webdriver、64/32 Geckodriver。
My configuration was as follows:
我的配置如下:
Linux: Centos 7 64bit, Window 7 64bit
Linux: Centos 7 64bit, Window 7 64bit
Firefox: 52.0.3
Firefox: 52.0.3
Selenium Webdriver: 3.4.0 (Windows), 3.8.1 (Linux Centos
)
Selenium Webdriver: 3.4.0 (Windows), 3.8.1 (Linux Centos
)
GeckoDriver: v0.16.0 (Windows), v0.17.0 (Linux Centos)
GeckoDriver: v0.16.0 (Windows), v0.17.0 (Linux Centos)
Working Code (Without Proxy Settings)
工作代码(无代理设置)
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();
Working Code (With Proxy Settings)
工作代码(使用代理设置)
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();
回答by Hongbo Miao
In my case, I only have Firefox Developer Edition but still throw same error.
就我而言,我只有 Firefox Developer Edition,但仍然抛出相同的错误。
After installing a standard Firefox version, it solves.
安装标准 Firefox 版本后,它解决了。
回答by Joe12
I had the same issue. My geckodriver was 32 bit and fireFox was 64. Resolved by updating geckodriver to 64 bit.
我遇到过同样的问题。我的 geckodriver 是 32 位,fireFox 是 64。通过将 geckodriver 更新到 64 位来解决。
回答by Priyansh gupta
I had exactly the same issue when i was using selenium firefox()
我在使用 selenium firefox() 时遇到了完全相同的问题
>> webdriver.Firefox()
it was not working : throwing error like "Unable to find a matching set of capabilities"
它不起作用:抛出错误,例如“无法找到一组匹配的功能”
Then i installed geckodriver.exeand that put that .exe file inside the both directory
然后我安装了geckodriver.exe并将该 .exe 文件放在两个目录中
C:\Users\<USER-NAME>\AppData\Local\Programs\Python\Python36\Scripts
and
和
C:\Users\<USER-NAME>\AppData\Local\Programs\Python\Python36\
and set these two paths in the environment setting
并在环境设置中设置这两个路径
then it started working
然后它开始工作
回答by AzyCrw4282
Here's the solution that solved it for me. Don't overlook this point: make sure you're using the correct 32/64 bit version of the binaries - it should be uniform - e.g. if the firefox is 64bit, so must be the geckodriver.
这是为我解决的解决方案。不要忽视这一点:确保您使用的是正确的 32/64 位版本的二进制文件 - 它应该是统一的 - 例如,如果 firefox 是 64 位,那么必须是 geckodriver。
回答by joiner
It seems like different workarounds are seem to make the error go away. After ensuring you have downloaded and installed the 64bit versions for Firefox and geckodriver.exe, update the PATH with the location of the geckodriver.exe. What may also help beforerunning the script, launch the geckodriver.exe which opens a cmd like window. Now if you run the py script, you shouldn't run into the error below:
似乎不同的解决方法似乎使错误消失。确保您已下载并安装 Firefox 和 geckodriver.exe 的 64 位版本后,使用 geckodriver.exe 的位置更新 PATH。在运行脚本之前还有什么帮助,启动 geckodriver.exe,它会打开一个类似 cmd 的窗口。现在,如果您运行 py 脚本,您应该不会遇到以下错误:
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
回答by Rohit Dhankar
Got the same error on a droplet at DigitalOcean - FireFox was not installed . Stack trace of error was as seen below -
在未安装 DigitalOcean-FireFox 的 Droplet 上遇到相同的错误。错误的堆栈跟踪如下所示 -
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":""}}')