如何通过Selenium在Chrome站点设置中启用允许Insecure content解决图片加载失败
解决Chrome“Insecure content”拦截导致图片无法加载的Selenium方案
如果你的自动化测试里遇到Chrome拦截HTTPS页面中的HTTP图片(提示“Insecure content”被Blocked,不是地址栏的“Not secure”提示),直接通过配置Chrome启动参数就能解决:
核心方案
初始化ChromeDriver时,给ChromeOptions添加--allow-running-insecure-content参数,允许浏览器加载HTTPS页面中的不安全HTTP资源。
代码示例
Python
from selenium import webdriver from selenium.webdriver.chrome.options import Options opts = Options() opts.add_argument("--allow-running-insecure-content") driver = webdriver.Chrome(options=opts) driver.get("你的测试页面地址")
Java
import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.chrome.ChromeOptions; public class FixInsecureContentBlock { public static void main(String[] args) { ChromeOptions opts = new ChromeOptions(); opts.addArguments("--allow-running-insecure-content"); ChromeDriver driver = new ChromeDriver(opts); driver.get("你的测试页面地址"); } }
参数说明
--allow-running-insecure-content 是Chrome官方支持的启动参数,专门用来绕过混合内容(HTTPS页面加载HTTP资源)的拦截限制,完全适配自动化测试场景,不需要额外手动修改浏览器设置。
拦截状态参考截图
被拦截时,DevTools控制台会输出如下错误:
Mixed Content: The page at 'https://xxx' was loaded over HTTPS, but requested an insecure image 'http://xxx'. This request has been blocked; the content must be served over HTTPS.
内容的提问来源于stack exchange,提问作者arjun
相关产品推荐
相关产品推荐


