我在macOS上使用Python3.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这个较低的版本从何而来?我很确定这就是为什么我有“缺失或无效的能力”。如果我以selenium开头:
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/‘是显式版本103的brew安装的chrome的位置。没什么区别。
解决方案
批准的答复不是解决办法,但它使我找到了解决办法。
我的webbot版本是最新的,但是它有一个非常不同的__init__方法:
def __init__(self, showWindow=True, proxy=None , downloadPath:str=None):经过进一步的检查,我发现driverPath属性(我之前尝试使用的)已经完全被设计掉了。因此,我决定在driverpath方法中打印内部变量__init__的值。它返回了以下内容:
project_root/virtualenvironment/lib/python3.9/site-packages/webbot/drivers/chrome_mac那是我的罪恶派对!我重新命名了该可执行文件,并将其替换为指向正确二进制文件的符号链接。起作用了。
发布于 2022-06-29 05:03:36
driver = Browser(True, None, '/usr/local/bin/')实际上设置的是downloadPath,而不是driverPath。显式使用参数名称
driver = Browser(driverPath='/usr/local/bin/')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)如果driverPath是None,它将设置为/{parent_folder_abs_path}/drivers/chrome_mac或/{parent_folder_abs_path}/drivers/,我猜您在那里有一个较旧的chromedriver版本。
https://stackoverflow.com/questions/72749695
复制相似问题