How to click button with FlaUI?

949 Views Asked by At

I am trying to automate an application installer using c# and FlaUI. I am able to successfully bring my desired application to the foreground, and seemingly set focus. I then gather all buttons, and prompt if I find a button named 'Next >' (the name I gathered from FlaUInspect v1.3.0)

The prompt occurs indicating a button with the correct name is being found - but the button.click event throws an exception.

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

I saw several threads suggesting that you should use Invoke() instead, so I've tried that, but get this exception:

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

Can anyone advise on how to actually click the button now that FlaUI has found it?

Code:

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();
            }           
        }
    }
}

Messagebox indicating the button is being found:

enter image description here

FlaUInspect output for the button in question:

enter image description here

0

There are 0 best solutions below