Home > Back-end >  VB.Net UI AutomationElement.Current.Name contains string, but VB.Net/Visual Studio only Matches Imme
VB.Net UI AutomationElement.Current.Name contains string, but VB.Net/Visual Studio only Matches Imme

Time:08-03

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 Let's play "Spot the difference" level 10,000. . .

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.

SEE?  It's RIGHT THERE - but String Comparisons do not pick it up. . .

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.

Do you see what I see?

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.

CodePudding user response:

1000 thanks go to user Jimi (from the comments in my question) for the suggestion the issue may be zero width spaces.

Doing some research on this topic specifically led me to find these 3 S.O. articles:

Simplest way to get rid of zero-width-space in c# string

How to identify zero-width character?

Zero Width Space character in string literals: Detect and/or prevent

Turns out the character u\200B as described by Jimi was the problem. Using similar approaches (and learning this character is detectable in Regex search queries, I've decided to search the control data I'm querying with Regex as follows:

If Regex.Replace(ControlFound.Current.Name,"\u200B","").Contains(titleCaption.Replace("*","") Or Regex.Replace(ControlFound.Current.Name,"\u200B","") Like titleCaption Then
  'Do something here
End if

  • Related