1

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

stuartd
  • 70,509
  • 14
  • 132
  • 163
Fuzz Evans
  • 2,893
  • 11
  • 44
  • 63
  • When using the managed wrapper for UIA there are some bugs when calculating the clickable point and I have had to in various projects of my own calculate the clickable point myself, move the mouse there and send a click. The other option is to use the InvokePattern directly instead of trying to move to and click. The InvokePattern should not care about the clickable point but can skip some logic based on how the developer who wrote the buttons logic implemented it (for example ran into buttons that care when your mouse enters them and you click). – Max Young Apr 12 '23 at 15:27
  • I'll take a look at defining my own clickable point, but since screen size may vary, I worry about misfires for hard coded points. The invoke option also errors as mentioned in the details. Have you had to deal with that? – Fuzz Evans Apr 13 '23 at 16:11
  • Sorry, I didn't mean to define your own clickable point. I meant writing the algorithm, using the bounding rectangle of the control, then finding the middle of the control, and finally using mouse movement APIs and SendKeys to move there and click it. I had to do this when using managed UIA (managed API is UIAv2) outside of FlaUI. – Max Young Apr 13 '23 at 19:02
  • Also, I just noticed in your example you tried the InvokePattern, which I missed in my previous comment; this would avoid the bug I was referring to, so if you have the same issue using InvokePattern, reimplementing the algorithm to find your own point to click, wouldn't do much good. – Max Young Apr 13 '23 at 19:03
  • One final suggestion, if you use Inspect.exe instead of FlaUIInspect.exe you can trigger the patterns from it. You could give this a try with Inspect.exe and see if it works from there to just give you another point of reference for if it's your code, FlaUI or a bug with UIA in general. – Max Young Apr 13 '23 at 19:05
  • I made a branch that implements a very shoddy version of what inspect does where it allowed you to use inspect to generically test certain patterns like Invoke. If the control you have selected in the tree supports the invoke pattern a unabled button will show up and if you click that it will attempt to invoke it. You can build this and use this branch of FlaUIInspect to see if the issue is in your code or something wrong with UIA/FlaUI https://github.com/maxinfet/FlaUInspect/tree/InvokeTest I hope this helps and hopefully I will commit something more robust for all patterns soon. – Max Young Apr 13 '23 at 20:56

0 Answers0