繁体   English   中英

关于使用 Python 的 webbot 的 Selenium 版本的错误

[英]Error about Selenium version using Python's webbot

我在 macOS 上使用 Python 3.9。 我正在尝试开始使用 webbot,但每次尝试时,我都会收到此错误:

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)

我使用的是 macOS 版本 10.4,因为我使用的是 32 位软件。 真正让我困惑的部分是为什么说chromedriver=2.39.562713 根据pip,驱动的版本是103.0.5060.53。 如果我导入selenium并尝试命令help(selenium) ,在输出结束时,我得到:

VERSION
    4.3.0

这个低版本是从哪里来的? 我很确定这就是为什么我有“缺失或无效的能力”。 如果我开始硒:

from selenium import webdriver
driver = webdriver.Chrome()

它按预期启动 Chrome。 显然我错过了一些东西。

我曾经用以下方式启动webbot:

from webbot import Browser
driver = Browser()

但是,为了确定起见,我将其更改为:

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

'/usr/local/bin/' 是 brew 安装的 chrome webdriver 的位置,它明确是 103 版。没有区别。

解决方案

批准的响应不是解决方案,但它使我找到了解决方案。

我的webbot版本是最新的,但它有一个非常不同的__init__方法:

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

经过进一步检查,我发现driverPath属性(我之前尝试使用的)完全被设计为消失了。 所以我决定在__init__方法中打印内部变量driverpath的值。 这返回了以下内容:

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

有我的罪人! 我重命名了该可执行文件,并在其位置放置了指向正确二进制文件的符号链接。 那行得通。

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

实际上设置的是downloadPath ,而不是driverPath 显式使用参数名称

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

来自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)

如果driverPathNone它将设置为/{parent_folder_abs_path}/drivers/chrome_mac/{parent_folder_abs_path}/drivers/ ,我猜你那里有一个旧的chromedriver版本。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM