selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities with Firefox 46 through Selenium

时光怂恿深爱的人放手 提交于 2019-11-26 17:51:00

As you are using Selenium 3.8.0 you have to use GeckoDriver mandatorily. But again as you are using Firefox v46.0 you have to set the capability marionette to False through DesiredCapabilities() as follows :

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()

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.0 lists FF55 or greater.

If you plan on using FF46, don't use geckodriver. Update your capabilities to have marionette set to False:

caps = DesiredCapabilities.FIREFOX.copy()
caps['marionette'] = False
driver=webdriver.Firefox(capabilities=caps)
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.

Simple solution is:

  1. Uninstall the existing Chrome/Firefox browser provided from Ubuntu : Go to Applications(top left corner)->Ubuntu software center-> search Chrome and uninstall it.
  2. Install latest browser.

For Chrome, steps are as follows:

  1. wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb

  2. sudo dpkg -i google-chrome-stable_current_amd64.deb

Done!

I got this error because the Firefox browser was not installed on my machine. You can download Firefox or download the Chrome driver here. If you use the Chrome drive, make sure you add it to the path (just like the geckodriver).

And the you can use it like this:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.python.org")
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!