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

如何在Selenium Standalone与WebdriverIO中配置接受不安全自签名证书

Got it! Let's fix that issue with accepting self-signed certificates when using Selenium Standalone and WebdriverIO. The key is configuring your WebdriverIO capabilities properly—here's how to do it step by step:

WebdriverIO配置核心:接受自签名证书

All the critical settings live in your WebdriverIO capabilities (either in a config file or directly when initializing the browser). You need to enable certificate acceptance for both the WebDriver session and the specific browser you're using.

Chrome浏览器配置

For Chrome, add the acceptInsecureCerts flag to your capabilities, plus Chrome-specific args to bypass certificate error prompts:

// 如果你用wdio.conf.js配置文件
exports.config = {
  // 其他配置项(比如specs、framework等)...
  capabilities: [{
    browserName: 'chrome',
    // 允许WebDriver接受不安全证书
    acceptInsecureCerts: true,
    'goog:chromeOptions': {
      args: [
        '--ignore-certificate-errors', // 忽略证书错误提示
        '--allow-insecure-localhost'   // 针对localhost的自签名证书额外放宽限制
      ]
    }
  }]
}

Firefox浏览器配置

For Firefox, similar logic applies but with Firefox-specific options:

exports.config = {
  // 其他配置项...
  capabilities: [{
    browserName: 'firefox',
    acceptInsecureCerts: true,
    'moz:firefoxOptions': {
      acceptInsecureCerts: true // Firefox专属的证书接受配置
    }
  }]
}

适配你代码的初始化示例

If you're initializing WebdriverIO directly in your script (like your code snippet shows), pass the capabilities when calling remote():

const webdriverio = require('webdriverio');

// 初始化浏览器会话
const browser = await webdriverio.remote({
  hostname: 'localhost', // Selenium Standalone默认地址
  port: 4444,
  path: '/wd/hub',
  capabilities: {
    browserName: 'chrome',
    acceptInsecureCerts: true,
    'goog:chromeOptions': {
      args: ['--ignore-certificate-errors', '--allow-insecure-localhost']
    }
  }
});

// 之后就可以正常访问带自签名证书的页面了
await browser.url('https://your-self-signed-cert-site.com');

关于Selenium Standalone的说明

You don't need extra configuration for the Selenium Standalone server itself here—all the certificate handling happens at the browser session level via WebdriverIO's capabilities. The Selenium server just acts as a middleman to pass these settings to the browser.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 04:12:41