# Selenium如何打开IE11浏览器 ## 前言 在Web自动化测试中,Selenium是最常用的工具之一。虽然现代浏览器如Chrome和Firefox更受欢迎,但在某些企业环境中仍需要支持Internet Explorer 11(IE11)。本文将详细介绍如何配置Selenium以启动IE11浏览器,并解决常见问题。 ## 环境准备 ### 1. 安装Selenium WebDriver 首先确保已安装Selenium的Python包: ```bash pip install selenium
从Selenium官方下载页面获取与你的系统匹配的版本: - 32位和64位版本需与IE安装版本一致 - 推荐下载最新稳定版(如3.141.59)
将下载的IEDriverServer.exe
放在: - Python脚本同级目录,或 - 添加到系统PATH环境变量中
from selenium import webdriver # 基本配置 driver = webdriver.Ie(executable_path='IEDriverServer.exe') driver.get("https://www.baidu.com") driver.quit()
IE对屏幕缩放敏感,需添加:
from selenium.webdriver.ie.options import Options options = Options() options.ignore_zoom_level = True driver = webdriver.Ie(options=options)
如果出现保护模式错误:
options = Options() options.require_window_focus = True options.introduce_flakiness_by_ignoring_security_domains = True
可通过add_argument()
添加:
options.add_argument('--ie-use-per-process-proxy') options.add_argument('--ie-force-create-process-api')
现象:This is the initial start page for the WebDriver server
解决方案:
options = Options() options.initial_browser_url = 'https://www.baidu.com'
添加忽略SSL错误配置:
options.add_argument('--ignore-certificate-errors')
需手动确保: 1. 关闭所有IE窗口 2. 设置系统显示缩放为100% 3. 在IE设置中禁用自动缩放
from selenium import webdriver from selenium.webdriver.ie.options import Options def open_ie11(): options = Options() options.ignore_zoom_level = True options.require_window_focus = True options.add_argument('--ie-use-per-process-proxy') driver = webdriver.Ie( executable_path='IEDriverServer.exe', options=options ) driver.get("https://www.baidu.com") return driver if __name__ == '__main__': driver = open_ie11() print("IE11成功打开!") driver.quit()
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main 新建DWORD值:TabProcGrowth = 0
虽然IE11逐渐退出历史舞台,但在遗留系统测试中仍是必要技能。通过合理配置IEDriverServer
和选项参数,可以稳定实现自动化操作。建议新项目优先考虑现代浏览器,仅在对旧系统维护时使用IE11方案。
提示:微软已停止IE支持,建议考虑Edge的IE模式作为替代方案。 “`
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。