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

WinAppDriver初始化WindowsDriver时抛出System.InvalidOperationException异常

WinAppDriver连接已启动记事本时的异常问题
try
{
    var caps = new DesiredCapabilities();
    var counter = 0;

    while (proc != null && proc.MainWindowHandle.ToInt32() == 0 && counter < 30)
    {
        Thread.Sleep(500);
        counter++;
    }

    var AppPath = @"C:\Windows\System32\notepad.exe";
    caps.SetCapability("appTopLevelWindow", proc?.MainWindowHandle.ToInt64().ToString("x"));
    caps.SetCapability("ms:experimental-webdriver", true);
    caps.SetCapability("app", AppPath);


    var urlWithPort = WinappServerUrl + selectedPort;
    var url = new Uri(urlWithPort);
    var driver = new WindowsDriver<WindowsElement>(url, caps, TimeSpan.FromMinutes(5));

    Thread.Sleep(5000);
    driver.Manage().Window.Maximize();
    Thread.Sleep(1000);
    return driver;
}
catch (Exception ex)
{
    throw new Exception($"Failed in SetupWinAppDriver. Url={WinappServerUrl + selectedPort}, Exception = {ex}");
}

在上述代码中,WinAppDriver与记事本均已成功启动,但执行var driver = new WindowsDriver<WindowsElement>(url, caps, TimeSpan.FromMinutes(5));时抛出异常。

错误信息:

System.InvalidOperationException: 'An unknown error occurred in the remote end while processing the command.'

已尝试的解决方法:

  • 开启Windows开发者模式
  • 以管理员身份运行WinAppDriver

但问题仍未解决。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.09 10:15:07