Slowat_Kela
Slowat_Kela

Reputation: 1511

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities error with ChromeDriver Chrome Selenium

First, machine and package specs: I am running:

ChromeDriver version 75.0.3770.140
Selenium: version '3.141.0'
WSL (linux subsystem) of windows 10

I am trying to run a chromebrowser through selenium. I found: these commands, to use selenium through google chrome.

I have a test directory, with only the chromedriver binary file, and the script, in it. The location of the directory is: /home/kela/test_dir/

I ran the code:

import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities


options = Options()
options.binary_location='/home/kela/test_dir/chromedriver'
driver = webdriver.Chrome(chrome_options = options,executable_path='/home/kela/test_dir/chromedriver')

The output from this code is:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found

Can anyone explain why I need capabilities when the same script works for others without capabilities? I did try adding:

chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')

but I got the same error. So I'm not sure what capabilities I need to add (considering it works for others without it?)

Edit 1: Addressing DebanjanB's comments below:

  1. Chromedriver is in the expected location. I am using windows 10. From here, the expected location is C:\Program Files (x86)\Google\Chrome\Application\chrome.exe; and this is where it is on my machine (I copied and pasted this location from the chrome Properties table).

  2. ChromeDriver is having executable permission for non-root users.

  1. I definitely have Google Chrome v75.0 installed (I can see that the Product version 75.0.3770.100)

  2. I am running the script as a non-root user, as my bash command line ends with a $ and not # (i.e kela:~/test_dir$ and not kela:~/test_dir#)

Edit 2: Based on DebanjanB's answer below, I am very close to having it working, but just not quite.

The code:

import selenium
from selenium import webdriver
from bs4 import BeautifulSoup
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location='/c/Program Files (x86)/Google/Chrome/Application/chrome.exe'
driver = webdriver.Chrome(options=options)
driver.get('http://google.com/')

Produces a dialog box that reads: Google Chrome cannot read and write to it's data directory: /tmp/.com/google.Chrom.gyw63s

So then I double checked my Chrome permissions and I should be able to write to Chrome:

Also, I can see that /tmp/ has a bunch of .com dirs in it:

.com.google.Chrome.4jnWme/ .com.google.Chrome.FdNyKP/ .com.google.Chrome.VAcWMQ/ .com.google.Chrome.ZbkRx0/ .com.google.Chrome.iRrceF/
.com.google.Chrome.A2QHHB/ .com.google.Chrome.G7Y51c/ .com.google.Chrome.WD8BtK/ .com.google.Chrome.cItmhA/ .com.google.Chrome.pm28hN/

However, since that seemed to be more of a warning than an error, I clicked 'ok' to close the dialog box, and a new tab does open in the browser; but the URL is just 'data:,'. The same thing happens if I remove the line 'driver.get('http://google.com')' from the script, so I know the warning/issue is with the line:

driver = webdriver.Chrome(chrome_options = options,executable_path='/home/kela/test_dir/chromedriver')

For example, from here, I tried adding:

options.add_argument('--profile-directory=Default')

But the same warning pops up.

Edit 3:

As edit 3 was starting to veer into a different question than specifically being addressed here, I started a new question here.

Upvotes: 5

Views: 47812

Answers (2)

Samer Ibrahim
Samer Ibrahim

Reputation: 25

you are importing the FireFox option not the Chrome Option, you have to make sure that you are importing the correct Option to start the selenium

for your case

change this :

from selenium.webdriver.firefox.options import Options

to this :

from selenium.webdriver.chrome.options import Options

Upvotes: 2

undetected Selenium
undetected Selenium

Reputation: 193058

This error message...

selenium.common.exceptions.SessionNotCreatedException: Message: session not created: No matching capabilities found

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


binary_location

binary_location set/get(s) the location of the Chrome (executable) binary and is defined as:

def binary_location(self, value):
    """
    Allows you to set where the chromium binary lives

    :Args:
     - value: path to the Chromium binary
    """
    self._binary_location = value

So as per your code trials, options.binary_location='/home/kela/test_dir/chromedriver' is incorrect.


Solution

If Chrome is installed at the default location, you can safely remove this property. Incase Chrome is installed at a customized location you need to use the options.binary_location property to point to the Chrome installation.

You can find a detailed discussion in Selenium: WebDriverException:Chrome failed to start: crashed as google-chrome is no longer running so ChromeDriver is assuming that Chrome has crashed

Effectively, you code block will be:

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

options = Options()
options.binary_location=r'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
driver = webdriver.Chrome(options=options, executable_path='/home/kela/test_dir/chromedriver.exe')
driver.get('http://google.com/')

Additionally, ensure the following:

  • ChromeDriver is having executable permission for non-root users.
  • As you are using ChromeDriver v75.0 ensure that you have the recommended version of the Google Chrome v75.0 as:

    ---------ChromeDriver 75.0.3770.8 (2019-04-29)---------
    Supports Chrome version 75
    
  • Execute the Selenium Test as non-root user.

Upvotes: 3

Related Questions