1

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.

Slowat_Kela
  • 1,193
  • 2
  • 15
  • 32
  • 1
    Please [edit the question](/posts/57092707/edit) to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – undetected Selenium Jul 18 '19 at 10:48
  • 1
    Thanks, I've hopefully made it more succint – Slowat_Kela Jul 18 '19 at 10:56
  • Thanks, I agree that there are other questions like this, I tagged one of them in the OP, you can see from my edit above based on DebanjanB's answer that none of the similar questions/suggestions seem to work for my issue and I wasn't sure what to do next except to just ask the community to show my specific issue (not that particular link you suggest though, as it's working with geckodriver/firefox and mine is chromedriver/chrome, although I agree that the solution that I eventually find is probably applicable across different drivers). – Slowat_Kela Jul 18 '19 at 13:15

1 Answers1

2

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.

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
  • Thanks, I tried all of these solutions, I've added edits to the OP, but I don't think they fix the issue in my case. – Slowat_Kela Jul 18 '19 at 13:43
  • @Slowat_Kela Checkout the answer update and let me know the status. – undetected Selenium Jul 18 '19 at 15:08
  • Thanks, i've edited my question above to update status. I am definitely closer, so I appreciate it. Let me know if you think we have now veered off topic from the original question and I should open a new question. I did look into my current issue myself before posting here, but I can't see a specific answer in the context of selenium and python, that would work in this situation. – Slowat_Kela Jul 19 '19 at 09:58
  • @Slowat_Kela i had same issue. did you get any solution ? – Balvant Ramani Mar 13 '21 at 16:15