This is my FindMenu code from the UI Automation exercise I am working on:
private ExpandCollapsePattern FindMenu(VTServiceMenu menu)
{
try
{
AutomationElement menuElement = _VTMainAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu.ToString()));
AutomationPattern[] autoPattern;
autoPattern = menuElement.GetSupportedPatterns();
ExpandCollapsePattern expPattern = menuElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
return expPattern;
}
catch (Exception e1)
{
LogEntry("Error " + e1.Message + " expanding menu in " + _VTMainAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu.ToString())));
throw new InvalidOperationException("Error " + e1.Message + " expanding menu in " + _VTMainAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu.ToString())));
return null;
}
}
Break after : autoPattern = menuElement.GetSupportedPatterns();
Examine: autoPattern[0].ProgrammaticName. Actual Value is "InvokePatternIdentifiers.Pattern" string, expected value is "ExpandCollapsePatternIdentifiers.Pattern" string
Exception on : ExpandCollapsePattern
This is the corresponding code from Kaila's Calculator example here on CodeProject:
private ExpandCollapsePattern FindMenu(CalculatorMenu menu)
{
AutomationElement menuElement = _calculatorAutomationElement.FindFirst(TreeScope.Descendants, new PropertyCondition(AutomationElement.NameProperty, menu.ToString()));
AutomationPattern[] autoPattern;
autoPattern = menuElement.GetSupportedPatterns();
ExpandCollapsePattern expPattern = menuElement.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern;
return expPattern;
}
It has the expected "ExpandCollapsePatternIdentifiers.Pattern" in autoPattern[0].ProgrammaticName. I have compared how he sets up _calculatorAutomationElement against my _VTMainAutomationElement, and his CalculatorMenu against my VTServiceMenu. If there are differences, then I have missed them.
I have done nothing with XAML - is that my missing link?