Mark Asztalos

Hi!

Lets use a BasePattern descendant, e.g. WindowPattern. WindowPattern.Pattern returns an AutomationPatterns, which has a name: ProgrammaticName property.

Is there a reverse way, to get to the WindowPattern class from a ProgrammaticName I should get to AutomationPattern from a name, and then to WindowPattern from the AutomationPattern. Should I implement a switch { } to make it work

Thanks, Mark



Re: Microsoft UI Automation getting AutomationPattern-s and BasePattern-s

Peter Donnelly - MSFT UE

It's difficult to answer this question without knowing what you are trying to accomplish. What is the scenario






Re: Microsoft UI Automation getting AutomationPattern-s and BasePattern-s

Mark Asztalos

I would like to make a user interface tester application. The test scenarios are written in an xml file, which can be edited by hand. Here, I want to write down some information, e.g.

<Event>
<AutomationElement>
button1
</AutomationElement>
<AutomationPattern>
AutomationPatternIdentifier.Button
</AutomationPattern>
<Action>
Invoke
</Action>
</Event>

When I read back the xml I would like to get the Type of ButtonPattern form the string AutomationPatternIdentifier.Button. I can do it now only if I know the ID of this concrete pattern. But in this case I have to write the ID to the xml file, and it can not be edited by hand easily.

My idea was to create a converter class, which has a property Dictionary<string, Type> and I can use it to retrieve the curent Type.





Re: Microsoft UI Automation getting AutomationPattern-s and BasePattern-s

Peter Donnelly - MSFT UE

Are you talking about InvokePattern There is no Button pattern. In any case, InvokePattern.Pattern is just a static identifier. You can't instantiate an InvokePattern object from it. You have to get the pattern object from the button.






Re: Microsoft UI Automation getting AutomationPattern-s and BasePattern-s

Mark Asztalos

I am sorry, yes I made a mistake. I try to explain the concrete problem here:

I hava a variable: string pattern = "InvokePattern"; I have an AutomationElement instance, button (AutomationElement button). I need the InvokePattern instance, which can be retrieved: InvokePattern p = button.GetCurrentPattern(InvokePattern.Pattern); So I need the InvokePattern.Pattern AutomationPattern, or the Type of InvokePattern, but I only know its name: "InvokePattern" as a string. If i had the ID of the AutomationPattern (InvokePattern.Pattern), I could use the AutomationPattern.LookupById method, but I know only its name, and my problem is there's no LookupByName method.

I hope, my problem is clear now.





Re: Microsoft UI Automation getting AutomationPattern-s and BasePattern-s

Peter Donnelly - MSFT UE

You can get that value by printing out InvokePattern.Pattern.Id.