1

I face a problem with ui-automation in WPF. I can not find items control through query in my test

rootElement.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.AutomationIdProperty, "AID_Positions")))

Its always return null. In the interface inspector, I see that the property is full and has correct value "AID_Positions".

My xaml

       <ItemsControl
            Grid.Row="1"
            Grid.Column="1"
            VirtualizingStackPanel.IsVirtualizing="True"
            ScrollViewer.CanContentScroll="True">
            <ItemsControl.ItemTemplate>
                <DataTemplate>
                    // data
                </DataTemplate>
            </ItemsControl.ItemTemplate>
            <ItemsControl.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel/>
                </ItemsPanelTemplate>
            </ItemsControl.ItemsPanel>
            <ItemsControl.Template>
                <ControlTemplate>
                    <Border
                        SnapsToDevicePixels="True">
                        <ScrollViewer
                           AutomationProperties.AutomationId="AID_Positions">
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </ItemsControl.Template>
        </ItemsControl>

I set 'AutomationProperties.AutomationId' property to ScrollViewer. What am I doing wrong?

lga
  • 194
  • 11

1 Answers1

2

Try using UIA verify tool to inspect your WPF UI and see if the tool can navigate to your ItemsControl. It might be possible that your ItemsControl is not a subtree of your rootElement. This tool should help you verify that. It might also be possible that there is some intermediate custom wpf element that doesn't support UIA and won't allow finding its descendant elements.

Nish26
  • 969
  • 8
  • 16