使用Selenium4启动Edge IE模式报错:找不到Internet Explorer
问题与解决方案
问题详情
- 应用仅能在Edge 105版本的IE兼容模式下正常运行,普通Edge浏览器无法适配
- 用Selenium 4编写代码启动Edge的IE模式时,弹出报错:"Internet Explorer cant be found. You need to re-install or re-enable Internet Explorer"
- 运行环境为Windows Server 2016 Oracle虚拟机,本机未安装IE 11,且Windows功能列表中找不到IE 11的启用选项
- 代码示例:
System.setProperty("webdriver.ie.driver", GlobalSettings.IE_DRIVER_PATH); InternetExplorerOptions IEOptionsEdge = setInternetExlopererForEdge(); driver = new InternetExplorerDriver(IEOptionsEdge); driver.get("https://www.bbc.co.uk/"); driver.manage().window().maximize(); private static InternetExplorerOptions setInternetExlopererForEdge() { InternetExplorerOptions IEOptions = new InternetExplorerOptions(); IEOptions.attachToEdgeChrome(); IEOptions.ignoreZoomSettings(); IEOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe"); return IEOptions; }
- 控制台报错信息:
Jun 15, 2023 10:03:42 AM org.openqa.selenium.remote.service.DriverService$Builder getLogOutput INFO: Driver logs no longer sent to console by default; https://www.selenium.dev/documentation/webdriver/drivers/service/#setting-log-output Exception in thread "main" org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. Host info: host: 'XYZ', ip: '123' Build info: version: '4.10.0', revision: 'c14d967899' System info: os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144' Driver info: org.openqa.selenium.ie.InternetExplorerDriver Command: [null, newSession {capabilities=[Capabilities {browserName: internet explorer, se:ieOptions: {ie.edgechromium: true, ie.edgepath: C:\\Program Files (x86)\\Micr..., ignoreZoomSetting: true}}]}] Capabilities {}
- 报错截图:

解决方案
1. 安装IE 11核心组件(必须步骤)
Edge的IE模式依赖IE 11的底层组件,即使不用桌面版IE也得安装。Windows Server 2016默认未预装,需手动离线部署:
- 下载匹配Windows Server 2016架构的IE 11离线安装包
- 右键以管理员身份运行安装包,完成后重启虚拟机
- 安装后无需创建IE快捷方式,核心组件已满足Selenium调用需求
2. 调整Selenium代码配置
优化InternetExplorerOptions参数,适配Edge IE模式:
private static InternetExplorerOptions setInternetExlopererForEdge() { InternetExplorerOptions IEOptions = new InternetExplorerOptions(); IEOptions.attachToEdgeChrome(); IEOptions.ignoreZoomSettings(); // 用正斜杠避免转义问题,或保留双反斜杠格式 IEOptions.withEdgeExecutablePath("C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"); // 强制启用IE模式测试参数 IEOptions.addCommandSwitches("--ie-mode-test"); // 禁用IE安全域限制(Windows Server默认开启,会阻止访问) IEOptions.introduceFlakinessByIgnoringSecurityDomains(); return IEOptions; }
- 确认
IEDriverServer.exe版本与Edge 105完全匹配,版本不兼容会导致启动失败 - 检查
GlobalSettings.IE_DRIVER_PATH指向的IEDriverServer.exe路径绝对正确
3. 修改Windows Server组策略
Windows Server的安全策略会限制IE模式运行,手动调整:
- 按下Win+R输入
gpedit.msc打开本地组策略编辑器 - 导航至计算机配置 > 管理模板 > Windows组件 > Internet Explorer
- 找到并启用"允许在IE模式下使用Microsoft Edge"策略
- 找到"Internet Explorer 增强安全配置",分别禁用管理员和用户的增强安全配置
4. 先手动验证Edge IE模式
确保手动打开Edge的IE模式能正常访问目标站点:
- 打开Edge设置 > 默认浏览器 > 允许在IE模式下重新加载网站,选择"允许"
- 添加目标应用的站点到IE模式站点列表,手动访问确认运行正常
- 手动启动无问题后再运行Selenium代码,排除浏览器本身的配置故障
内容的提问来源于stack exchange,提问作者Selenium Lover
相关产品推荐
相关产品推荐

