Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900