1

I have developed a python script with selenium with firefox webdriver. It is workign fine in my machine. but if i execute the same script in another machine it is giving the following error.

Traceback (most recent call last):
 File "insurance_web_monitor.py", line 13, in <module>
 driver = Firefox(executable_path='geckodriver', firefox_options=options)
 File "C:\Python34\lib\site-packages\selenium\webdriver\firefox\webdriver.py",
line 167, in __init__
 keep_alive=True)
 File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 156, in __init__
 self.start_session(capabilities, browser_profile)
 File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 251, in start_session
 response = self.execute(Command.NEW_SESSION, parameters)
 File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 320, in execute
 self.error_handler.check_response(response)
 File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 242, in check_response
 raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a
 matching set of capabilities

Here is my code

import os
from selenium.webdriver import Firefox
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as expected
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
if __name__ == "__main__":
 options = Options()
 cap = DesiredCapabilities().FIREFOX
 cap["marionette"] = False
 options.add_argument('-headless')
 driver = Firefox(executable_path='geckodriver', firefox_options=options, capabilities=cap)
 wait = WebDriverWait(driver, timeout=10)
 driver.get('http://www.google.com')
 driver.save_screenshot(
 os.path.join(os.path.dirname(os.path.realpath(__file__)), os.getcwd(), 'screenshot1.png'))
 wait.until(expected.visibility_of_element_located((By.NAME, 'q'))).send_keys('headless firefox' + Keys.ENTER)
 wait.until(expected.visibility_of_element_located((By.CSS_SELECTOR, '#ires a'))).click()
 print(driver.page_source)
 driver.quit()

The configurations in my machine are,

Windows => 7 Professional 64-bit
Python => 3.4.4
Selenium => 3.14
Firefox => 61.0.2
geckodriver => 0.21.0

The configurations in other machine are,

Windows => 7 Professional 64-bit
Python => 3.4.4
Selenium => 3.14
Firefox => 61.0.2
geckodriver => 0.21.0

Yes every configuration is exactly same. Though this seems silly it is not working and it's torturing me. Am i missing anything to consider between the machines? Thanks in advance.

undetected Selenium
194k44 gold badges304 silver badges385 bronze badges
asked Aug 24, 2018 at 10:55
6
  • have you tried caps['marionette'] = False Commented Aug 24, 2018 at 10:59
  • @SmashGuy Update the question with the error trace log. Commented Aug 24, 2018 at 11:00
  • @NarendraR, yes. But that is leading to selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Possible firefox version mismatch error. Modified the code in question Commented Aug 24, 2018 at 11:09
  • @DebanjanB added the error log Commented Aug 24, 2018 at 11:09
  • As you are using Firefox => 61.0.2 you can't use the configuration cap["marionette"] = False. Keep the configuration of marionette as default (true by default). Commented Aug 24, 2018 at 11:26

1 Answer 1

1

As per your question and code block as you are using the following Test Configuration:

  • Selenium => 3.14
  • geckodriver => 0.21.0
  • Firefox => 61.0.2

You have to use the capability marionette mandatorily. To achieve that either:

  • You can leave the capability marionette untouched as by default marionette is set to True.
  • You can also specify the capability marionette as follows:

    cap = DesiredCapabilities().FIREFOX
    cap["marionette"] = True
    

This usecase

This error message...

selenium.common.exceptions.SessionNotCreatedException: Message: Unable to find a matching set of capabilities

...implies that the GeckoDriver was unable to initiate/spawn a new WebBrowser i.e. Firefox Browser session.

There are numerous possibilities behind the error you are seeing and can be solved through any of the following steps mentioned below:

  • As you are on Windows OS you need to pass the key executable_path along with the value containing:

    • Absolute path of the GeckoDriver.
    • The Absolute path of the GeckoDriver should be mentioned through single quotes and single backward slash along with the raw (r) switch.
    • Include the extension of the GeckoDriver binary.
    • Your line of code will be:

      driver = Firefox(executable_path=r'C:\path\to\geckodriver.exe', firefox_options=options, capabilities=cap)
      

References

answered Aug 24, 2018 at 13:55
1
  • +1 for your time and explanation. Thanks. But this also doesn't work. I am unable to sort the error out. Commented Aug 25, 2018 at 17:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.