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"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="151" Width="190">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Button Content="1" />
<Button Content="2" />
</StackPanel>
<WrapPanel>
<Button Content="1" />
<Button Content="2" />
<Button Content="Button" />
</WrapPanel>
</StackPanel>
</Window>
Code: Select all
/form[@name='MainWindow']/button[1]
Code: Select all
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Button Content="Button" Grid.Row="1"/>
<Button Content="Button" Grid.Row="0"/>
</Grid>
Cheers,
David