Click here to Skip to main content
15,885,309 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Guys,

I am working with UI testing in WPF.

As we know for UI testing we need to know the controls name or unique ID in WPF.

Let me give examples sequentially,

1.

CSS
<Window x:Class="CustomControlProj.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="u1" Name="u1"
    xmlns:uc="clr-namespace:CustomControlLibrary;assembly=CustomControlLibrary">


I can identify window by name "u1" above.

2. <TextBox Name="text1" Grid.Row="2" Grid.Column="2" Text="{Binding ElementName=nud, Path=DecimalPlaces}"/>

I can get it using "text1" Name propert's value.

3. For Custom Controls,

MSIL
<Viewbox Grid.Row="3" Grid.ColumnSpan="3" Width="400">
  <uc:NumericUpDown x:Name="nud" Change=".01" Margin="10"/>
</Viewbox>


Here, NumericUpDown is CustomControl, I can identify it using OnCreateAutomationProperty of custom control class.

Butt......

4. If I have items control then how to identify unique id (Automation ID)...???

XML
<ItemsControl Grid.Column="0" Grid.Row="1" FontWeight="Normal" ItemsSource="{Binding Path=Configurations, Mode=TwoWay}"  Width="Auto">
      <ItemsControl.ItemTemplate>
          <DataTemplate>
              <Grid
                  Margin="20,20,20,20"
                  Width="Auto"
                  VerticalAlignment="Top">
                  <Grid.ColumnDefinitions>
                      <ColumnDefinition Width="Auto"></ColumnDefinition>
                      <ColumnDefinition Width="Auto"></ColumnDefinition>
                  </Grid.ColumnDefinitions>
                  <TextBlock
                      Foreground="Black"
                      HorizontalAlignment="Left"
                      Text="{Binding Path=Title, Mode=TwoWay}" />
                  <TextBox
                      Width="230"
                      FontWeight="Normal"
                      Text="{Binding Path=Value, Mode=TwoWay}"
                      Focusable="True"
                      Name="ADTConfiguration"
                      HorizontalAlignment="Left"
                      VerticalAlignment="Center">
                  </TextBox>
              </Grid>
          </DataTemplate>
      </ItemsControl.ItemTemplate>
  </ItemsControl>


Here, ItemsControl does not have the OncreateAutomationUI for ItemsControl control.

I need to fetch unique id for Items Control in WPF window for UI Automation?

Thank you :)
Posted

1 solution

Hello,

Can't you use the AutomationProperties.GetAutomationId static method ?
http://msdn.microsoft.com/en-us/library/ms606856.aspx[^]

You can check this link too: http://www.thinkfarahead.com/2010/07/assigning-automationids-dynamically-in.html[^]

Regards;
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900