Search code examples
c#wpf-controlsmicrosoft-ui-automationflaui

Getting the visibility of a progress bar in a WPF application using FlaUI Automation


I am automating a WPF app using FlaUI. I have a progressbar that is Inderminate. Once the progressbar gets Collapsed, The UI is loaded. I want to implement a Retry mechanism on the ProgressBar Visibility but I am not able to find the correct property through FlaUI

private ProgressBar LoadingStatus => _uiAutomation.FindElement("ShowProgress", Automation.FindBy.Id).AsProgressBar();

<ProgressBar AutomationProperties.AutomationId="ShowProgress"
                Grid.Row="1"
                Height="4"
                Margin="0"
                BorderThickness="0"
                IsIndeterminate="True"
                IsTabStop="False"
                ToolTip="Contacting Server, Please Wait..."
                Visibility="{Binding IsServerActive, Converter={StaticResource MwBoolToVisibilityConverterReverse}}" />

I want to implement a Retry.While((LoadingStaus_Is_Collapsed)=> )};but seems like I don't have access to the visibility property. How can I get it done?


Solution

  • The property that works here is IsOffScreen. The UIA framework provides this property as Visibility is a WPF property and not UIA. IsOffScreen returns True if the element is not currently on the screen else returns False. This is how I used it

    public bool LoadingStatusVisibiltity()
            {
                _logger.Info("Retrieving data from the server.Please wait!");
                if (LoadingStatus.IsOffscreen)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }