Skip to content
Igor Recio edited this page Aug 8, 2022 · 8 revisions

Here is a list with the most common issues and how to solve them.

FlaUI

Application.MainWindow / GetMainWindow does not return the correct Window

Unfortunately the main window of a process can be very "instable". Meaning that it can change during the runtime of your application. For example menus or contextmenus often become the processes main window. Also a splash screen can become the main window and sometimes also stays the main window, even if the splash screen is closed/hidden. Best would be to use app.GetAllTopLevelWindows(automation)[0] or another search from automation.GetDesktop() to get the correct window you want.

I get an error about interop.UIAutomationClient which cannot be found

This is the generated interop wrapper for the UIA3 automation types and commands. In general, FlaUI installs it automatically in your project but sometimes it can happen that it is added but it fails to set the Embed Interop Types property to false. So to fix this, just lookup the interop.UIAutomationClient in your projects references and set this property to false. This makes sure that the dll gets copied to the output.

I get "Access is denied" exceptions when trying to do anything.

This usually happens if your AUT (Application Under Test) runs elevated (as admin) and your test or application (which runs the FlaUI code) runs with less privileges. Start Visual Studio as administrator or at least the test or application as administrator.

Error "A 32 bit processes cannot access modules of a 64 bit process." when attaching to a process.

This happens if FlaUI runs in 32-bit but the application under test runs under 64-bit. Unchecked "Prefer 32-bit" in the projects build properties should fix that issue.

If you get this error in a unit test project, you should change your test runner's settings to run tests as 64-bit. Settings will differ depending on your test runner, but in Visual Studio you can find this in the Test menu:
Test > Test Settings > Default Processor Architecture > X64

A WPF TextBlock is not visible when it is in a template

This is an issue inside the TextBlockAutomationPeer. In that case, it returns false in its IsControlElementCore method and therefore is not visible (except for a raw tree walker). One solution is to create a subclass of the original TextBlock which fixes this issue which could look like:

public class AutomatisableTextBlock : TextBlock
{
    protected override AutomationPeer OnCreateAutomationPeer()
    {
        return new AlwaysVisibleTextBlockAutomationPeer(this);
    }
}

public class AlwaysVisibleTextBlockAutomationPeer : TextBlockAutomationPeer
{
    public AlwaysVisibleTextBlockAutomationPeer(TextBlock t) : base(t) { }

    protected override bool IsControlElementCore()
    {
         return true;
    }
}

Other solutions would be to create your own implementation of the TextBlock or use TextBox instead.
Sources:

When using DevExpress controls, some things (like tab content) are not updated

By default, DevExpress controls do not raise automation events, as these events may decrease the application performance. To make sure that the events are raised properly, set the ClearAutomationEventsHelper.IsEnabled static property to false on application startup (needs to be done in the application that is automated with FlaUI):

ClearAutomationEventsHelper.IsEnabled = false;

The bound command on a ToggleButton is not executed when it is toggled with Toggle()

This is an issue with the ToggleButtonAutomationPeer. So either create your own ToggleButton with a fixed AutomationPeer or just use Click().

FlaUInspect

Certain controls do not show in FlaUInspect or show strange errors

First you can try to start FlaUInspect as admin since it only can see controls which have the same or a lower privilege. Additionally check the bitness of your applications. There can be some problems if the app to inspect is 64 bit and FlaUInspect was started as 32 bit (example tree view items in WinForms).