You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用chrome.Options()启动Opera遇SessionNotCreatedError求助

解决Opera启动报错SessionNotCreatedError: Missing or invalid capabilities

你遇到的问题集中在几个操作细节上,逐一修正即可:

问题1:W3C能力值类型错误

你配置里的'w3c': 'true'是字符串类型,但Selenium要求该参数为布尔值true,字符串会被判定为无效配置。而且现代浏览器默认已经启用W3C协议,通常不需要手动设置这个参数。

问题2:Capabilities设置方式错误

Selenium 4的chrome.Options不需要用options.set('caps', ...)来传递capabilities,这种写法不符合当前版本的API规范,直接移除该语句即可。

问题3:启动参数遍历逻辑冗余

operaConfig.args是数组,用new Map(Object.entries(operaConfig.args))转Map再遍历完全没必要,直接遍历数组就能正确添加启动参数。

问题4:未指定Opera二进制文件路径(最关键)

chrome.Options默认会查找Chrome的可执行文件,而Opera的安装路径和Chrome不同,必须手动指定Opera的二进制文件路径,否则Driver找不到正确的浏览器程序,直接触发capabilities错误。


修正后的完整代码

配置部分:

const operaConfig = {
  'args': [
    '--no-sandbox',
    '--disable-dev-shm-usage',
    '--remote-debugging-port=9222'
  ],
  // 根据你的操作系统填写Opera的实际路径
  // Windows示例:'C:\\Program Files\\Opera\\launcher.exe'
  // Mac示例:'/Applications/Opera.app/Contents/MacOS/Opera'
  // Linux示例:'/usr/bin/opera'
  'binaryPath': '/path/to/your/opera'
};

获取选项的函数:

getOperaOptions() {
  let options = new chrome.Options();
  // 指定Opera的二进制文件路径
  options.setChromeBinaryPath(operaConfig.binaryPath);
  
  // 直接遍历启动参数数组
  operaConfig.args.forEach(arg => {
    options.addArguments(arg);
  });
  
  return options;
}

另外验证了你的版本匹配:Opera 100.0.4815.21对应Chromium 114,OperaDriver 114.0.5735.110和selenium-webdriver 4.10.0版本兼容,这部分没有问题。

内容的提问来源于stack exchange,提问作者Maxim G

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 14:10:11