0

这是我当前的代码,有时会失败,这给了我这个例外:

FlaUI.Core.dll 中出现“FlaUI.Core.Exceptions.PropertyNotSupportedException”类型的异常,但未在用户代码中处理。不支持请求的属性“名称 [#30005]”。

public void HandleImportSettingsWindow()
{
    using (var automation = new UIA3Automation())
    {
        var desktop = automation.GetDesktop();

        var window = Retry.WhileNull<Window>(
            () =>
            {
                var windows = desktop.FindAllChildren(cf => cf.ByControlType(ControlType.Window));
                AutomationElement window = null;
                foreach (var w in windows)
                {
                    // TODO: Handle The requested property 'Name [#30005]' is not supported exception.
                    // Sometimes it is possible to have untitled windows that don't have a "Name" property, such as splash screens.

                    // The window title can differ but it always includes the word "Import".
                    if (Regex.Match(w.AsWindow().Title, @"(Import)").Success)
                    {
                        window = w;
                        break;
                    }
                }
                return window.AsWindow();
            },
            timeout: TimeSpan.FromSeconds(10)
        ).Result;

        if (window != null)
        {
            window.SetForeground();
            window.Focus();
            Keyboard.Type(VirtualKeyShort.TAB);
            Thread.Sleep(400);
            Keyboard.Type(VirtualKeyShort.SPACE);
        }
    }
}

您对此问题有任何修复或解决方法吗?

4

0 回答 0