Python selenium.common.exceptions.SessionNotCreatedException:消息:无法通过 Selenium 找到与 Firefox 46 匹配的一组功能
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/47782650/
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.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with Firefox 46 through Selenium
提问by Eamonn Gormley
I must have some versions here that don't match up since I can't get Selenium with Python to fire up a Firefox web browser. I'm using an older version of Firefox because other people in here have the same old version of Python and for them the old version of Firefox works best.
我这里一定有一些不匹配的版本,因为我无法使用 Python 使用 Selenium 来启动 Firefox 网络浏览器。我正在使用旧版本的 Firefox,因为这里的其他人使用相同的旧版本 Python,而对他们来说,旧版本的 Firefox 效果最好。
Code:
代码:
from selenium import webdriver
from selenium import common
from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
Error:
错误:
Traceback (most recent call last):
File "scrapeCommunitySelenium.py", line 13, in <module>
driver=webdriver.Firefox(capabilities=DesiredCapabilities.FIREFOX)
File "/Library/Python/2.7/site-packages/selenium/webdriver/firefox/webdriver.py", line 158, in __init__
keep_alive=True)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 154, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 243, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities
Version info:
版本信息:
- Python 2.7.10
- Selenium 3.8.0
- Firefox 46.0
- GeckoDriver 0.19.1 (It's in a folder which is in my PATH environment variable)
- MacOS 10.12.6
- 蟒蛇 2.7.10
- 硒 3.8.0
- 火狐 46.0
- GeckoDriver 0.19.1(它位于我的 PATH 环境变量中的文件夹中)
- macOS 10.12.6
回答by DebanjanB
As you are using Selenium 3.8.0you have to use GeckoDriveras a mandatory. But again as you are using Firefox v46.0you have to set the capability marionetteas False
through DesiredCapabilities()
as follows :
当您使用Selenium 3.8.0 时,您必须强制使用GeckoDriver。但同样由于您使用的Firefox v46.0你必须设置能力的提线木偶的False
经过DesiredCapabilities()
如下:
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = False
browser = webdriver.Firefox(capabilities=cap, executable_path="C:\path\to\geckodriver.exe")
browser.get('http://google.com/')
browser.quit()
回答by Lucas Tierney
If you're going to use Geckodriver, you definitely need to use a newer version of Firefox. Frex: https://github.com/mozilla/geckodriver/releases/tag/v0.19.0lists FF55 or greater.
如果您打算使用 Geckodriver,您肯定需要使用更新版本的 Firefox。Frex:https: //github.com/mozilla/geckodriver/releases/tag/v0.19.0列出 FF55 或更高版本。
If you plan on using FF46, don't use geckodriver. Update your capabilities to have marionette set to False:
如果您打算使用 FF46,请不要使用 geckodriver。更新您的功能,将牵线木偶设置为 False:
caps = DesiredCapabilities.FIREFOX.copy()
caps['marionette'] = False
driver=webdriver.Firefox(capabilities=caps)
回答by Harun
I had this issue on my MacOS 10.5 Catalina.
What I did:
1. Installed the geckodriver using brew install geckodriver
2. Deleted/uninstalled my existing(OLD) Firefox browser (v.46) and installed v70.
3. tried:
我在 MacOS 10.5 Catalina 上遇到了这个问题。我做了什么: 1. 使用brew install geckodriver
2.安装了 geckodriver 2. 删除/卸载了我现有的(旧)Firefox 浏览器(v.46)并安装了 v70。3.试过:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('http://google.com')
The above worked fine with no errors, by launching Firefox and loading google.com
通过启动 Firefox 并加载 google.com,以上工作正常,没有错误
回答by simibac
I got this error because the Firefox browser was not installed on my machine. You can download Firefoxor download the Chrome driver here. If you use the Chrome drive, make sure you add it to the path (just like the geckodriver).
我收到这个错误是因为我的机器上没有安装 Firefox 浏览器。您可以在此处下载Firefox或下载 Chrome 驱动程序。如果您使用 Chrome 驱动器,请确保将其添加到路径中(就像 geckodriver 一样)。
And the you can use it like this:
你可以像这样使用它:
from selenium import webdriver
driver = webdriver.Chrome()
driver.get("http://www.python.org")
回答by sachin thakare
You can see similar error on Chrome as well. If you are seeing it on Ubuntu, the reason is probably you have a pre-installed version of Chrome and Firefox which is older. And you have downloaded the latest version of Chrome/Firefox driver.
您也可以在 Chrome 上看到类似的错误。如果您在 Ubuntu 上看到它,原因可能是您预装了旧版 Chrome 和 Firefox。并且您已经下载了最新版本的 Chrome/Firefox 驱动程序。
Simple solution is:
简单的解决办法是:
- Uninstall the existing Chrome/Firefox browser provided from Ubuntu : Go to Applications(top left corner)->Ubuntu software center-> search Chrome and uninstall it.
- Install latest browser.
- 卸载 Ubuntu 提供的现有 Chrome/Firefox 浏览器:转到应用程序(左上角)-> Ubuntu 软件中心-> 搜索 Chrome 并卸载它。
- 安装最新的浏览器。
For Chrome, steps are as follows:
对于Chrome,步骤如下:
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
Done!
完毕!
回答by Hiren Namera
There are some possible reasons for that error like:
该错误有一些可能的原因,例如:
- Firefox is installed in your system
- Firefox access is admin only
- Firefox is not installed with same name
- Firefox version is not updated
- Firefox 已安装在您的系统中
- Firefox 访问权限仅限管理员
- Firefox 未安装同名
- Firefox 版本未更新