Click here to Skip to main content
13,089,207 members (78,759 online)
Rate this:
 
Please Sign up or sign in to 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.

<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,

<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)...???

<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 23-May-11 22:31pm

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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;
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy |
Web04 | 2.8.170813.1 | Last Updated 3 Nov 2011
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100