FlaUI如何点击按钮?

问题描述 投票:0回答:0

我正在尝试使用 C# 和 FlaUI 自动化应用程序安装程序。 我能够成功地将我想要的应用程序带到前台,并且似乎设置了焦点。 然后我收集所有按钮,并提示我是否找到名为“Next >”的按钮(我从 FlaUInspect v1.3.0 收集的名称)

出现提示,表明正在找到具有正确名称的按钮 - 但 button.click 事件抛出异常。

FlaUI.Core.Exceptions.NoClickablePointException: Exception of type 'FlaUI.Core.Exceptions.NoClickablePointException' was thrown.

我看到几个线程建议你应该改用 Invoke() ,所以我试过了,但是得到了这个异常:

System.InvalidOperationException: Operation is not valid due to the current state of the object.

现在 FlaUI 已经找到了,谁能建议如何实际点击按钮?

代码:

using (var automation = new UIA2Automation())
{   
    var mainWindow = application.GetMainWindow(automation);

    if (mainWindow != null)
    {
        mainWindow.SetForeground();
        mainWindow.Focus();
        var buttons = mainWindow.FindAllDescendants(x => x.ByControlType(FlaUI.Core.Definitions.ControlType.Button));
        foreach (var b in buttons)
        {
         if (b.Name == "Next >")
            {
                MessageBox.Show("found: " + b.Name);
                //I'm using click OR invoke, not both. Including both as reference
                b.Click();
                
                var invokePattern = b.Patterns.Invoke.Pattern;                           
                invokePattern.Invoke();
            }           
        }
    }
}

指示找到按钮的消息框:

FlaUInspect 相关按钮的输出:

c# ui-automation installshield flaui
© www.soinside.com 2019 - 2024. All rights reserved.