Home > Software engineering >  Error about Selenium version using Python's webbot
Error about Selenium version using Python's webbot

Time:06-30

I'm using Python 3.9 on macOS. I'm trying to start using webbot, but every time I try, I get this error:

selenium.common.exceptions.SessionNotCreatedException: Message: session not created 
exception: Missing or invalid capabilities
  (Driver info: chromedriver=2.39.562713 
(dd642283e958a93ebf6891600db055f1f1b4f3b2),platform=Mac OS X 10.14.6 x86_64)

I'm using macOS version 10.4 because I use 32 bit software. The part that really puzzles me is why is says chromedriver=2.39.562713. According to the pip, the driver's version is 103.0.5060.53. If I import selenium and try the command help(selenium), towards the end of the output, I get:

VERSION
    4.3.0

Where does this lower version come from? I'm pretty sure that's why I have "missing or invalid capabilities." If I start selenium with:

from selenium import webdriver
driver = webdriver.Chrome()

It starts Chrome as expected. Obviously I'm missing something.

I used to start webbot with:

from webbot import Browser
driver = Browser()

But then, just to be sure, I changed it to:

from webbot import Browser
driver = Browser(True, None, '/usr/local/bin/')

'/usr/local/bin/' being the location of a chrome webdriver installed by brew that is explicitly version 103. No difference.

Solution

The approved response was not the solution, but it led me to the solution.

My version of webbot is the latest, but it has a very different __init__ method:

    def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):

Upon further inspection, I saw that the driverPath attribute (that I had tried to use earlier) was completely gone by design. So I decided to print the value of the inner variable driverpath inside the __init__ method. This returned the following:

project_root/virtualenvironment/lib/python3.9/site-packages/webbot/drivers/chrome_mac

There was my guilty party! I renamed that executable and in its place put a symbolic link to the correct binary. That worked.

CodePudding user response:

driver = Browser(True, None, '/usr/local/bin/')

actually sets the downloadPath, not the driverPath. Use the parameter name explicitly

driver = Browser(driverPath='/usr/local/bin/')

From webbot.py

class Browser:
    def __init__(self, showWindow=True, proxy=None , downloadPath:str=None, driverPath:str=None, arguments=["--disable-dev-shm-usage","--no-sandbox"]):

        if driverPath is not None and isinstance(driverPath,str):
            driverPath = os.path.abspath(driverPath)
            if(not os.path.isdir(driverPath)):
                raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), driverPath)

        if driverPath is None:
            driverfilename = ''
            if sys.platform == 'linux' or sys.platform == 'linux2':
                driverfilename = 'chrome_linux'
            elif sys.platform == 'win32':
                driverfilename = 'chrome_windows.exe'
            elif sys.platform == 'darwin':
                driverfilename = 'chrome_mac'
            driverPath = os.path.join(os.path.split(__file__)[0], 'drivers{0}{1}'.format(os.path.sep, driverfilename))
        
        self.driver = webdriver.Chrome(executable_path=driverPath, options=options)

If driverPath is None it will set to /{parent_folder_abs_path}/drivers/chrome_mac or /{parent_folder_abs_path}/drivers/, I'm guessing you have an older chromedriver version there.

  • Related