You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Jenkins服务器无法启动IE兼容模式Edge的问题求助

问题描述

我有一段启动IE兼容模式Edge的Selenium代码:

case EDGE_COMPATIBILITY: {
    logMessage(MessType.INFO, "Running Edge under compatibility mode.");
    
    InternetExplorerOptions ieOptions = new InternetExplorerOptions();
    
    ieOptions.introduceFlakinessByIgnoringSecurityDomains();
    ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
    ieOptions.attachToEdgeChrome();
    ieOptions.destructivelyEnsureCleanSession();
    
    System.setProperty("webdriver.ie.driver", projectLoc + "\\src\\externaljars\\selenium\\edgedriver\\iedriverserver.exe");
    
    try {
        logMessage(MessType.INFO, "About to create 'webdr'");
        webdr = new InternetExplorerDriver(ieOptions);
        
        logMessage(MessType.INFO, "Sleeping for 10 seconds.");
        Thread.sleep(10000);
        logMessage(MessType.INFO, "Done sleeping ...");
        
        webdr.manage().window().maximize();

        Thread.sleep(1000);     

    } catch (Exception e) {
        e.printStackTrace();
    }
    
    break;
}

这段代码本地运行正常,日志如下:

TITLE Executing Method launchBrowser  Time: [1:38:34PM]
INFO TEMP LOG MESSAGE : Data Source: DATABASE  Browser: EDGE_COMPATIBILITY URL: null
INFO TEMP LOG MESSAGE :  Browser: EDGE_COMPATIBILITY
INFO Running Edge under compatibility mode.
INFO About to create 'webdr'
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
Started InternetExplorerDriver server (32-bit)
4.7.0.0
Listening on port 23537
Only local connections are allowed
INFO Sleeping for 10 seconds.
INFO Done sleeping ...

但在Jenkins服务器上运行时抛出SessionNotCreatedException,日志如下:

14:02:26    [testng] TITLE Executing Method launchBrowser  Time: [4:2:26PM]
14:02:26    [testng] INFO TEMP LOG MESSAGE : Data Source: DATABASE  Browser: EDGE_COMPATIBILITY URL: null
14:02:26    [testng] INFO TEMP LOG MESSAGE :  Browser: EDGE_COMPATIBILITY
14:02:26    [testng] INFO Running Edge under compatibility mode.
14:02:26    [testng] INFO About to create 'webdr'
14:02:27    [testng] Started InternetExplorerDriver server (32-bit)
14:02:27    [testng] 4.7.0.0
14:02:27    [testng] Listening on port xxxxxx
14:02:27    [testng] Only local connections are allowed
14:05:28    [testng] org.openqa.selenium.SessionNotCreatedException: Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure. 
14:05:28    [testng] Host info: host: 'xxxxxxxxxx', ip: 'xx.xx.xx.xx'
14:05:28    [testng] Build info: version: '4.6.0', revision: '79f1c02ae20'
14:05:28    [testng] System info: os.name: 'Windows Server 2016', os.arch: 'amd64', os.version: '10.0', java.version: '11.0.11'
14:05:28    [testng] Driver info: org.openqa.selenium.ie.InternetExplorerDriver
14:05:28    [testng] Command: [null, newSession {capabilities=[Capabilities {browserName: internet explorer, se:ieOptions: {ie.edgepath: C:\Program Files (x86)\Micr..., ignoreProtectedModeSettings: true}}], desiredCapabilities=Capabilities {browserName: internet explorer, se:ieOptions: {ie.edgepath: C:\Program Files (x86)\Micr..., ignoreProtectedModeSettings: true}}}
14:05:28    [testng] Capabilities {}
14:05:28    [testng]    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:559)

奇怪的是,当我登录到Jenkins服务器的桌面时运行,就不会出现异常,仿佛有屏幕输出时才能完成实例化。想问这是Jenkins的限制吗?还是需要额外配置InternetExplorerOptions参数?


解决方案

1. 开启Jenkins服务的交互桌面权限

这是最可能的原因:Jenkins默认以服务形式运行,没有桌面交互权限,而Edge兼容模式启动时需要桌面环境渲染。

  • 打开Windows服务管理器,找到Jenkins服务
  • 右键选择「属性」→「登录」选项卡
  • 勾选「允许服务与桌面交互」,然后重启Jenkins服务
  • 若Jenkins使用系统账户运行,建议切换到带桌面权限的本地管理员账户运行服务

2. 补充配置InternetExplorerOptions参数

在现有配置基础上,添加以下参数适配服务器环境:

// 强制启用窗口聚焦,保证桌面交互
ieOptions.requireWindowFocus();
// 忽略浏览器缩放比例,避免服务器环境缩放设置影响
ieOptions.setCapability("ignoreZoomSetting", true);
// 确保会话干净,避免残留进程干扰
ieOptions.setCapability("ie.ensureCleanSession", true);

3. 检查驱动与浏览器版本匹配

  • 确保IEDriverServer版本(4.7.0.0)与Edge浏览器版本完全兼容,建议使用对应Edge版本的IEDriverServer
  • 将服务器上的Edge浏览器更新到最新稳定版,避免版本不兼容导致启动失败

4. 服务器IE环境配置

  • 打开服务器上的IE浏览器,进入「Internet选项」→「安全」选项卡
  • 确保所有区域的「保护模式」设置一致(全部开启或全部关闭),即使代码中设置了忽略安全域,服务器环境仍需手动调整
  • 在「高级」选项卡中关闭IE的「增强保护模式」

内容的提问来源于stack exchange,提问作者DeZaelez

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.03 12:51:56