I feel very stupid and newb about this, but nowhere can I find any insights on what I'm experiencing. If this question has been asked or answered already, please send a link - the answer escapes me.
Referencing an S.O. Article regarding UI Automation and MSEdge I posted a while ago, I am able to route my way through some things, but I have come across a really strange phenomenon that I simply cannot explain.
I developed a routine that is marvelous at finding most of the Apps/Windows that I need, but it fails HARD when searching for Microsoft Edge
, with a unique exception to this. . .
The routine snip outlined below will only be called if I cannot find it using other methods. In this method however, if I send a string in titleCaption
that I have personally typed out as "*Microsoft Edge*"
it will fail to find Microsoft Edge
no matter what, in spite of the Debug.Print
line below showing the text Microsoft Edge
in the rootwinds(a).Current.Name
!!
rootwinds = AutomationElement.RootElement.FindAll(TreeScope.Children, New PropertyCondition(AutomationElement.LocalizedControlTypeProperty, windowType(windowType_Int)))
For a = 0 To rootwinds.Count - 1
Debug.Print(rootwinds(a).Current.Name)
If rootwinds(a).Current.Name Like titleCaption Then
app2Find = rootwinds(a)
ElseIf rootwinds(a).Current.Name.Contains(titleCaption.Replace("*", "")) Then
app2Find = rootwinds(a)
End If
Next
The ONLY way I am able to have this method find Microsoft Edge
is if I take the Debug.Print
output from the Immediate
window . . . copy it, and paste it into the place I'm specifying this string. . . then magically, it finds it. I do NOT understand.
The strings in this example LOOK IDENTICAL to these eyes:
In this example, the red underlined string is the Typed version, and the green underlined is the copied/pasted version directly from the Immediate
window. . . The Function
FindApp
is a Boolean Function
that returns True
when either the IntPtr Handle
or AutomationElement
(first 2 Param's) are Not Nothing
. . . The first iteration returns False
. . . the second returns True
(I put them both in an And
If
statement to show their likeness to one another - normally the function is called once. . . Additionally, the code for pulling the Handle
etc. is not the part that fails - I have isolated it to this instance.)
This is an example of where I find the text in the Immediate Window.
This issue also happens with other strings I am pulling from MSEdge
like the string of the sign-in options. . . I can see the text plain as day but cannot get a match without using the results from Immediate
window.
Above is another example of the Immediate Window where I can get this text, but only after seeing it in the Immediate window and copying/pasting.
To make this even stranger . . . this method works fine for finding any other app/window I need. . . just not MSEdge.
I get the phenomenon when using Imports.System.Windows.Automation
as well as using the UIAComWrapper.dll
located here on GitHub using NuGet
. Visual Studio is VS 2019 Professional, laptop is Windows 10.