winappdriver,appium,c#,连接到Windows 10上已经运行的窗口

发布于 2025-01-23 11:45:54 字数 1771 浏览 4 评论 0原文

我正在尝试使用C#.NET在Windows 10上使用WinapPdriver和Appium自动使用应用程序。

我正在尝试附加到已经运行的窗口上,但我一直找不到方法。我在网络上尝试了许多示例,包括从github网站for winappdriver。

https://github.com/microsoft/winappdriver 过程,但是当我尝试连接时,它会失败。它声称这不是顶级窗口。

具体错误是:“ openqa.selenium.webdriverexception:'b2c不是顶级窗口句柄'“

我已经尝试过“应用”条目,而不是“ apptoplevelwindow”,并且它不起作用。

这是我正在运行的代码:

    private void grabWindowsProcesses2()
    {
        int number = 0;
        _txtBxOutput.Text = "";
        IntPtr myAppTopLevelWindowHandle = new IntPtr();
        foreach (Process clsProcess in Process.GetProcesses())
        {
            number++;

            _txtBxOutput.Text += number.ToString() + ") " + clsProcess.ProcessName + "\n";
            if (clsProcess.ProcessName.Contains("VisualBoyAdvance"))
            {
                myAppTopLevelWindowHandle = clsProcess.Handle;
                break;
            }
        }

        var appTopLevelWindowHandleHex = myAppTopLevelWindowHandle.ToString("x");

        AppiumOptions appCapabilities = new AppiumOptions();           
        appCapabilities.AddAdditionalCapability("platformName", "Windows");            
        appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
        appCapabilities.AddAdditionalCapability("appTopLevelWindow", appTopLevelWindowHandleHex);

        /*
         * Error I get here is: OpenQA.Selenium.WebDriverException: 'b2c is not a top level window handle'
         */
        _visualBoyAdvance = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);            
    }

有人对我做错了什么有任何想法吗?我是自动台式机的新手。我不知道,也许有更好的方法。

I'm trying to automate the use of an application with WinAppDriver and Appium on Windows 10 using C# .Net.

I'm trying to attach to an already running Window and I've been failing to find a way. I've tried many examples on the web, including from the github site for the WinAppDriver.

https://github.com/microsoft/WinAppDriver

I finally found a way to get a handle for the process, but when I try to connect it fails. It claims it's not a top level window.

The specific error is: "OpenQA.Selenium.WebDriverException: 'b2c is not a top level window handle'"

I've tried the "app" entry instead of "appTopLevelWindow", and it did not work.

Here is the code I'm running:

    private void grabWindowsProcesses2()
    {
        int number = 0;
        _txtBxOutput.Text = "";
        IntPtr myAppTopLevelWindowHandle = new IntPtr();
        foreach (Process clsProcess in Process.GetProcesses())
        {
            number++;

            _txtBxOutput.Text += number.ToString() + ") " + clsProcess.ProcessName + "\n";
            if (clsProcess.ProcessName.Contains("VisualBoyAdvance"))
            {
                myAppTopLevelWindowHandle = clsProcess.Handle;
                break;
            }
        }

        var appTopLevelWindowHandleHex = myAppTopLevelWindowHandle.ToString("x");

        AppiumOptions appCapabilities = new AppiumOptions();           
        appCapabilities.AddAdditionalCapability("platformName", "Windows");            
        appCapabilities.AddAdditionalCapability("deviceName", "WindowsPC");
        appCapabilities.AddAdditionalCapability("appTopLevelWindow", appTopLevelWindowHandleHex);

        /*
         * Error I get here is: OpenQA.Selenium.WebDriverException: 'b2c is not a top level window handle'
         */
        _visualBoyAdvance = new WindowsDriver<WindowsElement>(new Uri("http://127.0.0.1:4723"), appCapabilities);            
    }

Does anyone have any ideas about what I'm doing wrong? I'm fairly new to automating a desktop. I don't know, maybe there is a better way.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文