Getting actual automation pattern knowing only ProgrammaticName
-
Tuesday, May 15, 2012 11:41 AM
Hello
as it stated in MSDN I'm getting the supported automation patterns for the automation element via GetSupportedPatterns function, but it returns me a list of AutomationPattern objects, which have a property called ProgrammaticName, that contains the concrete type of a pattern as string like "InvokePatternIdentifiers.Pattern". I want to use a particular pattern for the element but I don't know the actual type as I have it only in general form (in AutomationPattern). Is there any way to get the actual InvokePattern object from this AutomationPattern object knowing only the ProgrammaticName property?
Thanks in advance
- Edited by HayNar Tuesday, May 15, 2012 11:47 AM
All Replies
-
Wednesday, May 16, 2012 1:32 PM
I have implemented my own method for this purpose using a big switch operator. This solves my problem, but maybe there is another solution?
public object GetActualAutomationPattern(AutomationElement element, AutomationPattern pattern) { switch (pattern.ProgrammaticName) { case "DockPatternIdentifiers.Pattern": return element.GetCurrentPattern(DockPattern.Pattern) as DockPattern; case "ExpandCollapsePatternIdentifiers.Pattern": return element.GetCurrentPattern(ExpandCollapsePattern.Pattern) as ExpandCollapsePattern; case "GridPatternIdentifiers.Pattern": return element.GetCurrentPattern(GridPattern.Pattern) as GridPattern; case "GridItemPatternIdentifiers.Pattern": return element.GetCurrentPattern(GridItemPattern.Pattern) as GridItemPattern; case "InvokePatternIdentifiers.Pattern": return element.GetCurrentPattern(InvokePattern.Pattern) as InvokePattern; case "MultipleViewPatternIdentifiers.Pattern": return element.GetCurrentPattern(MultipleViewPattern.Pattern) as MultipleViewPattern; case "RangeValuePatternIdentifiers.Pattern": return element.GetCurrentPattern(RangeValuePattern.Pattern) as RangeValuePattern; case "ScrollPatternIdentifiers.Pattern": return element.GetCurrentPattern(ScrollPattern.Pattern) as ScrollPattern; case "ScrollItemPatternIdentifiers.Pattern": return element.GetCurrentPattern(ScrollItemPattern.Pattern) as ScrollItemPattern; case "SelectionPatternIdentifiers.Pattern": return element.GetCurrentPattern(SelectionPattern.Pattern) as SelectionPattern; case "SelectionItemPatternIdentifiers.Pattern": return element.GetCurrentPattern(SelectionItemPattern.Pattern) as SelectionItemPattern; case "TablePatternIdentifiers.Pattern": return element.GetCurrentPattern(TablePattern.Pattern) as TablePattern; case "TableItemPatternIdentifiers.Pattern": return element.GetCurrentPattern(TableItemPattern.Pattern) as TableItemPattern; case "TogglePatternIdentifiers.Pattern": return element.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern; case "TransformPatternIdentifiers.Pattern": return element.GetCurrentPattern(TransformPattern.Pattern) as TransformPattern; case "ValuePatternIdentifiers.Pattern": return element.GetCurrentPattern(ValuePattern.Pattern) as ValuePattern; case "WindowPatternIdentifiers.Pattern": return element.GetCurrentPattern(WindowPattern.Pattern) as WindowPattern; default: return pattern; } }the pattern is the required AutomationPattern object that needs to being tested and the element is that AutomationElement from which I have got that pattern
- Marked As Answer by HayNar Wednesday, May 16, 2012 1:32 PM


