windows Winappdriver正在引发System.InvalidOperationException错误

wn9m85ua  于 2023-11-21  发布在  Windows
关注(0)|答案(1)|浏览(149)
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}");
}

字符串
在上面的代码中,var driver = new WindowsDriver<WindowsElement>(url, caps, TimeSpan.FromMinutes(5));这一行在Winappdriver和记事本成功启动后抛出。
错误为System.InvalidOperationException: 'An unknown error occurred in the remote end while processing the command.'
已尝试启用开发人员模式。已尝试在管理员模式下运行winappdriver。

jm81lzqq

jm81lzqq1#

如果您想附加到现有流程,请尝试删除以下行:

  • 使用““ms:experimental-webdriver”参数不稳定
  • “应用程序”只需要如果你想运行应用程序的WinAppDriver
caps.SetCapability("ms:experimental-webdriver", true);
caps.SetCapability("app", AppPath);

字符串
如果您想运行应用程序并创建会话,请删除:

caps.SetCapability("appTopLevelWindow", proc?.MainWindowHandle.ToInt64().ToString("x"));
caps.SetCapability("ms:experimental-webdriver", true);

相关问题