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

Java自动化测试:如何为Selenium ChromeDriver禁用混合内容?

在ChromeDriver中禁用混合内容限制的实现方案

可以在ChromeDriver中实现同样的操作,通过配置ChromeOptions来禁用混合内容限制,对应Java代码示例如下:

import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import java.util.Map;

// 初始化Chrome选项
ChromeOptions chromeOptions = new ChromeOptions();
// 允许加载HTTPS页面中的HTTP主动内容(如脚本、iframe等)
chromeOptions.addArguments("--allow-running-insecure-content");
// 设置偏好,允许所有混合内容(包括显示类内容如图片)
chromeOptions.setExperimentalOption("prefs", Map.of(
    "profile.default_content_setting_values.mixed_content", 1
));

// 启动ChromeDriver
ChromeDriver driver = new ChromeDriver(chromeOptions);

参数说明:

  • --allow-running-insecure-content:对应Firefox中的security.mixed_content.block_active_content=false,解除对HTTPS页面中HTTP主动执行内容的阻止。
  • profile.default_content_setting_values.mixed_content=1:对应Firefox中的security.mixed_content.block_display_content=false,1表示允许所有混合内容加载,确保显示类资源正常渲染。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.27 18:57:35