1

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.

GeorgiG
  • 1,018
  • 1
  • 13
  • 29

1 Answers1

2

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.

GeorgiG
  • 1,018
  • 1
  • 13
  • 29
  • Thanks for the solution. Funny thing is that if we add `AutomationProperties.Name="-"` to the Grid element, it works too. So I wonder why making AutomationName a non-null and non-empty string works. – Chun Lin May 23 '20 at 08:56
  • @ChunLin I would guess that it can't really cast the actual content into a string and that's why it fails. I'd guess that even AutomationProperties.Name="" will work (if you're not planning to get it by name). – GeorgiG May 28 '20 at 11:05
  • 1
    Thanks @GeorgiG. I tried with `AutomationProperties.Name=""`, it didn't work. So I guess it must be not just non-null, but also non-empty. – Chun Lin May 29 '20 at 19:41