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
相关产品推荐
相关产品推荐

