When using the managed UI Automation, I cannot get the elements automatically from MS Teams. I am assuming there HAS to be a method to launch Teams or a flag to set that allows accessibility to be utilized. If I run Inspect.exe FIRST, and then try my code below, the commented line for CalendarButton
works FLAWLESSLY. If I DO NOT run Inspect.exe then the for Loop I was hoping would iterate all buttons fails to enumerate ANYTHING!!! I've scoured MSDN and the internet wide over and cannot find anything relating on how to develop something that will enable those features.
Anyone have any ideas? Like I said - the code below worked flawlessly (without the need for the for loop and using only the commented lines to find the calendar button.)
Edit
I have found out that since Teams is ALSO based on Chromium, if you run it from command line with --force-renderer-accessibility
it will allow enumeration, but you MUST kill all existing MSTeams sessions for it to work. (I have to give partial credit to this SO Article as it allowed me to open a dev side of Teams to see this flag is available (see image below code sample). Although this is "nice" to know, it's not getting at the root of my question (albeit, I'll still probably use this). What I'm actively looking for is HOW Inspect is able to trigger this accessibility feature on demand
Public Shared Sub QuickTeamsTry()
Dim MainWinds As AutomationElementCollection
Dim TeamsMainWindow As AutomationElement
Dim TeamsMainHandle As IntPtr
Dim MainTeamWindow As AutomationElement
Dim MainTeamHandle As IntPtr
Dim ChatPanel As AutomationElement
Dim ChatComp As AutomationElement
Dim CalendarButton As AutomationElement
TeamsMainHandle = WindowsEnumerator.FindWindowEx(Nothing, Nothing, Nothing, "Teams.exe")
If TeamsMainHandle = IntPtr.Zero Then
MainWinds = AutomationElement.RootElement.FindAll(TreeScope.Children, New PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "pane"))
For a = 0 To MainWinds.Count - 1
If MainWinds(a).Current.Name.Contains("Teams, Main Window") Then
TeamsMainWindow = MainWinds(a)
TeamsMainHandle = MainWinds(a).Current.NativeWindowHandle
Exit For
End If
Next
Else
TeamsMainWindow = AutomationElement.FromHandle(TeamsMainHandle)
End If
MainTeamWindow = TeamsMainWindow.FindFirst(TreeScope.Descendants, New PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "document"))
If Not IsNothing(MainTeamWindow) Then MainTeamHandle = MainTeamWindow.Current.NativeWindowHandle
Dim Buttons As AutomationElementCollection = MainTeamWindow.FindAll(TreeScope.Descendants, New PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "button"))
For a = 0 To Buttons.Count
'Gives me index out of bounds exception at _0_!!!
Debug.Print(Buttons(a).Current.Name)
Next a
'CalendarButton = MainTeamWindow.FindFirst(TreeScope.Descendants, New AndCondition(New PropertyCondition(AutomationElement.LocalizedControlTypeProperty, "button"),
' New PropertyCondition(AutomationElement.NameProperty, "Calendar Toolbar")))
'WindowsEnumerator.SetForegroundWindow(TeamsMainHandle)
'Click_Object(CalendarButton)
'Cannot even invoke the button since it was never set
'Dim invoker As InvokePattern = TryCast(CalendarButton.GetCurrentPattern(InvokePattern.Pattern), InvokePattern)
'invoker.Invoke()
End Sub