Spy doesn't capture hierarchy WPF controls are placed in

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
Posts: 3
Joined: Thu Oct 28, 2010 9:34 am

Spy doesn't capture hierarchy WPF controls are placed in

Post by HMITest » Thu Dec 05, 2013 9:02 am

Dear all,

we are asked to write an automated GUI test for a WPF application. The controls placed on the WPF form are not named and often have the same content/text displaying - but they are hierarchically placed in different "panels". Below I have included the XAML source code of a minimal working example showing the basic structure:

Code: Select all

<Window x:Class="SomeButtons.MainWindow"
        Title="MainWindow" Height="151" Width="190">
  <StackPanel Orientation="Vertical">
    <StackPanel Orientation="Horizontal">
      <Button Content="1" />
      <Button Content="2" />
      <Button Content="1" />
      <Button Content="2" />
      <Button Content="Button" />
Until now the application - which is now made with WPF - was of the WinForms type, so that we could distinguish the buttons having the same button text by their position in the "panels" hierarchy (the Rx Path was different for them). As it seems the hierarchy is not persisted in WPF after compilation: The Ranorex Spy arranges the 5 controls on the same level, distinguishing them only by the index - here it's "1":

Code: Select all

The order is the exact one like the ordner in which they appear in XAML.
Even when using a Grid like this:

Code: Select all

    <RowDefinition />
    <RowDefinition />
  <Button Content="Button" Grid.Row="1"/>
  <Button Content="Button" Grid.Row="0"/>
where the second Button is placed above the first button due to explicit Grid.Row="..." declaration, the order in which the Buttons got their indices in Spy is the order in which they appear in XAML: The button at the top of the window has the index 2 and the one place at the bottom was assigned index 1.
This gives us a bit of a headache, since we cannot be as deterministic as with WinForms before, but maybe you have a solution for us? Would be awesome. Thanks!

You do not have the required permissions to view the files attached to this post.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA

Re: Spy doesn't capture hierarchy WPF controls are placed in

Post by Support Team » Tue Dec 10, 2013 1:52 pm

Hello HMITest,

The problem is that StackPanes is a layout panel and no ui element and there that there is no UIAutomation implementation available out of the box.
I am afraid that you have to create an Automation Peer for that element in order to recognize the element using Ranorex.