I’ve isolated the issue in this test app:
XAML
<Window
x:Class="UI.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:UI"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button x:Name="MyButton" Content="Button"/>
<ComboBox x:Name="MyCombobox">
<x:String>Blue</x:String>
<x:String>Green</x:String>
<x:String>Red</x:String>
<x:String>Yellow</x:String>
</ComboBox>
</StackPanel>
</Window>
C#
using Microsoft.UI.Xaml;
namespace UI
{
public sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
This FlaUI test successfully finds a button, but after picking an item from a combobox it can no longer find the same button:
using FlaUI.Core;
using FlaUI.Core.AutomationElements;
using FlaUI.Core.Input;
using FlaUI.UIA3;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;
namespace Tests
{
[TestClass]
public class UnitTest1
{
[UITestMethod]
public void TestCombobox()
{
// Find the app
var app = Application.Attach("path to UI package exe");
Assert.IsNotNull(app, "Can't find app");
// Find the window
var window = app.GetMainWindow(new UIA3Automation());
Assert.IsNotNull(window, "Can't find window");
// Look for the button
var button1 = window.FindFirstDescendant(cf => cf.ByAutomationId("MyButton"));
Assert.IsNotNull(button1, "Can't find button the first time");
// Pick the combobox item
window.FindFirstDescendant(cf => cf.ByAutomationId("MyCombobox")).AsComboBox().Select(1);
Wait.UntilInputIsProcessed();
// Look for the button again
var button2 = window.FindFirstDescendant(cf => cf.ByAutomationId("MyButton"));
Assert.IsNotNull(button2, "Can't find button the second time"); // Fails here
}
}
}
Is this an issue with FlaUI, or am I misunderstanding something about how the UI automation tree works?