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

RemoteWebDriver启动Edge IE模式遇SessionNotCreatedException求助

问题描述

需要对仅支持Edge IE模式的应用执行自动化测试,当前在本地(localhost)运行selenium-server-4.8.2.jar独立服务器,项目依赖selenium-java 4.1.3版本。

运行Selenium服务器的命令

java -"Dwebdriver.ie.driver=C:\Users\abc\Downloads\IEDriverServer_Win32_4.8.1\IEDriverServer.exe" -jar .\selenium-server-4.8.1.jar standalone

尝试的两种实现方式及问题

  1. 使用InternetExplorerOptions的实现
public static void runIEWithEdge() throws MalformedURLException {
        String remoteUrl = "http://localhost:4444";

        InternetExplorerOptions edgeOptions = new InternetExplorerOptions();
        edgeOptions.attachToEdgeChrome();
        edgeOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");

        WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), edgeOptions);
        driver.get("http://demo.borland.com/gmopost");
        driver.findElement(By.name("bSubmit")).click();
        driver.quit();
    }

运行后浏览器未启动,Selenium服务器抛出org.openqa.selenium.SessionNotCreatedException:

11:02:28.393 WARN [SeleniumSpanExporter$1.lambda$export$1] - Unable to create session: Could not start a new session. null
Host info: host: 'YCSLAPTEMP', ip: '192.168.16.118'
Build info: version: '4.8.1', revision: '8ebccac989'
System info: os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '17.0.2'
Driver info: driver.version: unknown
...(异常栈省略)
  1. 使用EdgeOptions的实现
public static void runEdge( String[] args ) throws MalformedURLException {
        String remoteUrl = "http://localhost:4444";

        EdgeOptions edgeOptions = new EdgeOptions();
        edgeOptions.setCapability("ie.edgechromium", true);
        edgeOptions.setCapability("ie.browserCommandLineArguments", "-ms-edge-legacy-emulation-mode-ie11");

        WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), edgeOptions);
        driver.get("http://demo.borland.com/gmopost");
        driver.findElement(By.name("bSubmit")).click();
        driver.quit();
    }

此方式可正常启动Edge,但无法进入IE模式。


解决方案

1. 统一版本兼容

Selenium Server、IEDriverServer、selenium-java依赖版本必须一致,当前版本差异会导致兼容性问题:

  • 将项目的selenium-java依赖升级至4.8.2
  • 下载对应版本的IEDriverServer_Win32_4.8.2.exe替换现有文件

2. 修正Selenium Server启动命令

原命令的-D参数格式错误,调整为:

java -Dwebdriver.ie.driver=C:\Users\abc\Downloads\IEDriverServer_Win32_4.8.2\IEDriverServer.exe -jar .\selenium-server-4.8.2.jar standalone

3. 远程环境下的Edge IE模式正确配置

远程环境中,必须通过InternetExplorerOptions配置Edge IE模式,核心代码如下:

public static void runEdgeIEModeRemotely() throws MalformedURLException {
    String remoteUrl = "http://localhost:4444";

    InternetExplorerOptions ieOptions = new InternetExplorerOptions();
    // 启用Edge IE模式绑定
    ieOptions.attachToEdgeChrome();
    // 指定远程机器上的Edge可执行文件路径
    ieOptions.withEdgeExecutablePath("C:\\Program Files (x86)\\Microsoft\\Edge\\Application\\msedge.exe");
    // 强制启用Edge Chromium兼容模式
    ieOptions.setCapability("ie.edgechromium", true);
    // 禁用IE增强保护模式(远程环境必备配置)
    ieOptions.introduceFlakinessByIgnoringSecurityDomains();

    WebDriver driver = new RemoteWebDriver(new URL(remoteUrl), ieOptions);
    try {
        driver.get("http://demo.borland.com/gmopost");
        driver.findElement(By.name("bSubmit")).click();
    } finally {
        driver.quit();
    }
}

4. 远程机器前置配置

  • 确保远程机器上已安装Edge浏览器,且路径与代码中指定的一致
  • 开启Edge IE模式:打开Edge → 设置 → 默认浏览器 → 允许在IE模式下重新加载网站,将测试站点添加至IE模式站点列表
  • 确保IEDriverServer所在目录有读写权限,远程机器防火墙允许4444端口通信

关键注意点

  • Edge IE模式的自动化必须依赖InternetExplorerOptions和IEDriverServer,不可混用EdgeOptions配置
  • withEdgeExecutablePath指定的是远程机器上的Edge路径,而非本地路径
  • 若仍出现Session创建失败,查看Selenium Server日志获取详细错误信息,排查IEDriver启动权限、路径错误等问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 12:53:16