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

Selenide自动跳转HTTPS而非指定HTTP,如何关闭Chrome默认HTTPS特性?

解决Chrome自动将HTTP转为HTTPS导致Selenide测试URL异常的问题

Chrome 63+默认开启的自动HTTPS升级特性会把HTTP请求强制转为HTTPS,导致你设置的http://example.com被自动替换。可以通过配置Chrome浏览器参数来禁用这个特性,以下是两种可行方案:

方案一:在测试代码中配置ChromeOptions

直接在测试类的初始化代码里添加Chrome参数,覆盖默认行为:

import com.codeborne.selenide.Configuration;
import org.openqa.selenium.chrome.ChromeOptions;

public class YourTestClass {
    static {
        ChromeOptions chromeOptions = new ChromeOptions();
        // 禁用自动HTTPS升级
        chromeOptions.addArguments("--no-https-upgrade");
        // 允许加载HTTP不安全内容
        chromeOptions.addArguments("--allow-running-insecure-content");
        // 忽略证书错误(如果测试站点无有效HTTPS证书)
        chromeOptions.addArguments("--ignore-certificate-errors");
        
        Configuration.browserCapabilities = chromeOptions;
        Configuration.baseUrl = "http://example.com";
    }
}

方案二:通过VM参数配置(无需修改代码)

在IntelliJ的VM参数中添加以下配置:

-Dselenide.baseUrl=http://example.com
-Dchrome.options="--no-https-upgrade --allow-running-insecure-content"

参数说明

  • --no-https-upgrade:核心参数,直接关闭Chrome的自动HTTPS升级逻辑
  • --allow-running-insecure-content:解除对HTTP资源的加载限制,避免测试页面资源被拦截
  • --ignore-certificate-errors:当测试环境的HTTP站点存在证书问题时,可添加此参数跳过证书校验

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.23 14:54:53