I want to use Windows AutomationElement
s to simulate Userinput during testing.
My particulat usecase is manupilating a ListBox selection and from what I find online I will need an AutomationElement for my listbox in order to manipulate it.
Suppose I had a window like this:
<Window x:Class="CryptoAdmin_Test.Helper.FreshWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:CryptoAdmin_Test.Helper">
<StackPanel>
<UserControl x:FieldModifier="public" x:Name="FindMe" />
</StackPanel>
</Window>
Since I have a reference to the UserControl I should be able to find it without starting my search from the desktop (AutomationElement.RootElement
).
What is the fastest way to get an AutomationElement
for my window.FindMe
UserControl
?
Using AutomationElement.RootElement.FindFirst(...);
would start with the desktop and I do not see a generic way that would make this search fast without any possibility for false positives.