Search code examples
c#uwpappiumappium-desktopwinappdriver

Can't inspect Grids/StackPanels/Custom Controls in WinAppDriver & locate them by AccessibilityId with Appium


My UWP app shows very limited part of the elements when inspected (neither with inspector.exe nor with Appium Client's Inspector). As a consequence, trying to locate them with Appium's FindElementByAccessibilityId results with NoSuchElementException.

Example:

<Page [namespaces]>

    <Page.Resources>
       [Resources]
    </Page.Resources>

    <Grid AutomationProperties.AutomationId="CreationModeRoot">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button x:Name="BackButton" />

            <StackPanel x:Name="MainToolsPanel"
                        Orientation="Horizontal">
                <controls:ToolBarButton x:Name="DrawingToolBallPen" />
                <controls:ColorSelectorDropDown x:Name="ColorPaletteDropDown">
                    <PathIcon Width="44"
                              Height="44"
                              Data="{StaticResource ColorToolIcon}">
                    </PathIcon>
                </controls:ColorSelectorDropDown>
            </StackPanel>
        </Grid>

        <ScrollViewer x:Name="Scroll">
            <inkCanvas:InkVectorCanvas x:Name="InkVectorCanvas" />
        </ScrollViewer>
    </Grid>
</Page>

From the above code, the only successfully inspected elements are the BackButton, DrawingToolBallPen & Scroll. Neither the CreationModeRoot, nor the MainToolsPanel, nor the nor the InkVectorCanvas are detected.

Please tell me how to properly construct my view.


Solution

  • I found the solution:

    AutomationId and AutomationName are automatically mapped to x:Name and Content properties. If the content property is not string, most of the time inspecting tools fail to detect them. Overwriting AutomationName using AutomationProperties.Name PropertyPath resolves that problem.