如何配置Selenium仅启动Internet Explorer(禁用Edge兼容模式)
如何配置Selenium仅启动原生Internet Explorer而非Edge IE模式?
问题背景
在仅安装Internet Explorer 22H2、未部署Microsoft Edge的离线终端中,使用Selenium调用IE时,出现了启动Edge IE模式的异常情况(实际无Edge却触发该逻辑),当前使用IEDriver版本为4.8.1.0,现有代码如下:
from selenium import webdriver import time from selenium.webdriver.ie.service import Service from selenium.webdriver.common.by import By # CONFIGURACION s=Service(r"C:\Users\User\Desktop\programacion\CLARO\drivers\IEDriverServer.exe") # ie_options = webdriver.IeOptions() # ie_options.attach_to_edge_chrome = True # ie_options.edge_executable_path = "C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe" # driver = webdriver.Ie(service=s, options=ie_options) driver = webdriver.Ie(service=s) driver.maximize_window() # PERSONALIZACION driver.get("http://python.org") driver.close()
解决方法
1. 显式配置IeOptions禁用Edge IE模式关联
Selenium 4.x版本的IEDriver默认会尝试检测并关联Edge的IE模式,即使终端未安装Edge,也可能因系统残留配置触发该逻辑。需通过IeOptions显式禁用关联:
from selenium import webdriver import time from selenium.webdriver.ie.service import Service from selenium.webdriver.common.by import By # CONFIGURACION s=Service(r"C:\Users\User\Desktop\programacion\CLARO\drivers\IEDriverServer.exe") # 配置IE选项,强制使用原生IE ie_options = webdriver.IeOptions() ie_options.attach_to_edge_chrome = False # 关键:禁用与Edge IE模式的关联 ie_options.ie_switches = "-extoff" # 禁用IE扩展,避免干扰 ie_options.add_argument("-private") # 可选:使用隐私模式,规避缓存或配置冲突 driver = webdriver.Ie(service=s, options=ie_options) driver.maximize_window() # PERSONALIZACION driver.get("http://python.org") driver.close()
2. 检查并修改系统层面的IE强制关联设置
部分离线终端可能通过组策略或注册表配置了强制用Edge打开IE内容,需手动调整:
- IE设置检查:打开Internet Explorer → 点击右上角设置图标 → 选择「Internet选项」→ 切换到「高级」标签页,确保「启用增强保护模式」处于关闭状态(该模式可能导致IEDriver无法正常启动原生IE)。
- 注册表配置:按下
Win+R输入regedit打开注册表编辑器,定位到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Internet Explorer\Main,右键新建「DWORD(32位)值」,命名为DisableEdgeIEIntegration,将值设为1,强制系统使用原生IE而非Edge IE模式。
内容的提问来源于stack exchange,提问作者Mr Usher
相关产品推荐
相关产品推荐

