Windows10下IE11浏览器Selenium启动后无法访问URL问题求助
我来帮你一步步排查这个IE11启动后会话丢失、无法访问URL的问题,结合你的代码和报错信息,咱们先梳理清楚核心问题,再给出针对性解决方案:
问题复现场景
- 系统:Windows 10 64位
- Selenium版本:2.53.1
- IEDriverServer版本:3.8.0 64位
- 现象:IE浏览器能正常启动,但执行
driver.get()时抛出SessionNotFoundException
你的Selenium代码
System.setProperty("webdriver.ie.driver","D:\\Automation\\Drivers\\IEDriverServer.exe"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); capabilities.setCapability("ignoreZoomSetting", true); WebDriver driver = new InternetExplorerDriver(); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); Thread.sleep(3000); driver.get("http://google.co.in");
报错信息
Started InternetExplorerDriver server (64-bit) 3.8.0.0
Listening on port 25160
Only local connections are allowed
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" org.openqa.selenium.remote.SessionNotFoundException: session null does not exist (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 2 milliseconds
Build info: version: '2.53.1', revision: 'a36b8b1', time: '2016-06-30 17:37:03'
System info: host: 'TS-39', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_91'
核心原因分析
- 版本不兼容:你用的Selenium 2.53.1是2016年的老版本,而IEDriverServer是3.8.0,两者版本差距过大,通信协议不匹配直接导致会话丢失。
- IE11安全配置未达标:Win10下的IE11有严格的安全限制,比如保护模式、缩放比例等设置不符合Selenium的控制要求。
- 代码关键疏漏:你配置了
DesiredCapabilities但没有传入InternetExplorerDriver的构造方法,等于白设置了这些兼容参数。
分步解决方案
1. 统一Selenium与IEDriverServer版本
Selenium和IEDriverServer的版本必须严格匹配,建议升级Selenium到3.8.0(和你的IEDriver版本一致),或者降级IEDriver到2.53.1,避免版本不兼容导致的通信问题。
2. 配置IE11的安全设置
打开IE11的Internet选项,完成以下设置:
- 切换到「安全」标签页,确保四个区域(Internet、本地Intranet、受信任站点、受限制站点)的「启用保护模式」勾选状态完全一致(全部开启或全部关闭)。
- 确认浏览器缩放比例为100%(尽管代码里设置了忽略缩放,手动保证100%能避免潜在的会话异常)。
- 切换到「高级」标签页,取消勾选「增强保护模式」(Win10下该模式会干扰Selenium的会话建立)。
3. 完善代码配置(修复关键疏漏)
修改你的代码,把配置好的capabilities传入驱动构造方法,并补充更多兼容IE11的参数:
System.setProperty("webdriver.ie.driver","D:\\Automation\\Drivers\\IEDriverServer.exe"); DesiredCapabilities capabilities = DesiredCapabilities.internetExplorer(); // 忽略缩放设置 capabilities.setCapability(InternetExplorerDriver.IGNORE_ZOOM_SETTING, true); // 忽略保护模式差异(建议先手动统一保护模式,再用这个兜底) capabilities.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true); // 禁用原生事件,避免会话异常 capabilities.setCapability(InternetExplorerDriver.NATIVE_EVENTS, false); // 强制启用IE的自动化权限 capabilities.setCapability("requireWindowFocus", true); // 关键:把配置好的capabilities传入驱动构造方法 WebDriver driver = new InternetExplorerDriver(capabilities); driver.manage().window().maximize(); driver.manage().timeouts().implicitlyWait(10,TimeUnit.SECONDS); driver.get("http://google.co.in");
4. 尝试切换IEDriverServer位数
Win10 64位系统下,64位的IEDriverServer有时会有兼容性问题,建议下载32位版本的IEDriverServer 3.8.0替换现有驱动,再测试。
额外提示
- 尽量避免使用
Thread.sleep(),改用显式等待(WebDriverWait)来等待页面元素加载,稳定性会更高。 - 确保IE11是最新版本,及时安装系统补丁,减少系统层面的兼容性问题。
内容的提问来源于stack exchange,提问作者Sagar

