Is there any real difference between the XAML Propertys AutomationProperties.AutomationId and AutomationProperties.Name?
And most importantly, is there any reason to choose one over the other?
Neither of them seem unique to me although msdn says so about .AutomationId: "The string that uniquely identifies the specified element."
I tested a WPF application with 2 buttons each with the same .AutomationId within the same tree path, and the .AutomationId is not unique at all.
XAML allows me to give them the same .AutomationId, and if I search for them via the following code, it returns both Buttons.
PropertyCondition cond = new PropertyCondition(AutomationElement.AutomationIdProperty, "myButton");
returnedAEs = myMainWindow.FindAll(TreeScope.Children, cond);
foreach (AutomationElement element in returnedAEs)
{
//...enters here 2 times
}
XAML:
<Window ... >
<Grid ...>
<Button ... AutomationProperties.AutomationId="myButton"/>
<Button ... AutomationProperties.AutomationId="myButton"/>
<Window ... >
</Grid>
</Window>