UI elements cannot be identified correctly (Windows Form)

Ask general questions here.
Rika L.
Posts: 17
Joined: Thu Nov 19, 2020 10:03 am

UI elements cannot be identified correctly (Windows Form)

Post by Rika L. » Sat Feb 27, 2021 12:00 am

Hello,
I have some problems with UI identification. I use Ranorex (9.4.1) to test an Application, which is programed with Windows Form. I have found a problem when I let Ranorex to identify a MenuItem named 'Edit': When I change its text, Ranorex cannot recognize it anymore after changing.
And then I go back to Visual Studio to see the 2 properties 'Name' and 'Text' of the MenuItem 'Edit':
Its 'Name' is: editToolStripMenuItem
Its 'Text' is: Edit
Ranorex should take 'Name' (editToolStripMenuItem) as accessibleName to identify this UI element, but it takes 'Text' (Edit) as its accessibleName. This is why Ranorex cannot recognize this UI element after its text is changed.

MenuItem is MSAA. And I also find, buttons which are recognized by Ranorex as WinForm Control don't have the same problem. Ranorex takes 'Name' but not 'Text' as accessibleName. For example, a button:
Its 'Name' is: button1
Its 'Text' is: Save
Ranorex take 'Name' (button1) as accessibleName to identify this UI element.

Can someone help me? :) The Snapshots are in the attachment. One is for the MenuItem 'Edit', the other one is for the button 'Save'.

Best Regards
Rika
Attachments
Snapshots_Menuitem_Edit_MSAA.rxsnp
(24.04 KiB) Downloaded 10 times
Snapshots_Button_Save_WindowsFormControl.rxsnp
(24.27 KiB) Downloaded 9 times

kOoO
Posts: 26
Joined: Wed Oct 17, 2018 11:15 am
Location: Zlin, CR

Re: UI elements cannot be identified correctly (Windows Form)

Post by kOoO » Sat Feb 27, 2021 5:52 am

So there are two states.

First state (from which snapshot is taken?), before you change the menuitem text through the application. In this state, the MenuItem has these attributes:
AccessibleName="Edit"
Text="Edit"

In this state you track the element using Ranorex and it creates repo item with ".../MenuItem[@AccessibleName='Edit']"

Then second state, after you make the change in application, the same MenuItem has now these attributes:
AccessibleName="editToolStripMenuItem"
Text="Edit"

Now the element is not trackable because its AccessibleName changed.

Did I get it right?

If yes I don't think that selecting the element based just on AccessibleName is enough since it's not static. There shouldn't be any correlation between AccessibleName and other parameters like Name or Text - from application's code perspective it's just a solo string property that could be set to whatever.

BTW could you also post the snapshot after the change - when the AccessibleName is "editToolStripMenuItem"?

Rika L.
Posts: 17
Joined: Thu Nov 19, 2020 10:03 am

Re: UI elements cannot be identified correctly (Windows Form)

Post by Rika L. » Mon Mar 01, 2021 6:32 pm

Hallo kOoO,
thank you very much to your answer! To make my question more clearly I have prepared more Snapshots and pictures. I will upload all of them in next post : )

Rika L.
Posts: 17
Joined: Thu Nov 19, 2020 10:03 am

Re: UI elements cannot be identified correctly (Windows Form)

Post by Rika L. » Tue Mar 02, 2021 9:38 am

Briefly speaking, I have now a problem with UI element identification. But until now this problem happened only on the UI elements which are MSAA UI elements. When the Ranorex identifies one UI element, it is very important to let Ranorex to choose a good property (i.e. ControlName) to create a XPath, which can be used even after the text of the UI element is changed, otherwise I must change my program after the text is changed.
I have used Visual Studio to create a small application to show my problem. This application looks like that:
Image
https://ibb.co/YT6KPK4 (To avoid the pictures cannot be showed I paste their url here)
This application has a menu item named 'Edit' and a button named 'Save'.
I will change the two buttons' names to 'Edit_2' and 'Save_2' to show the after change status. It looks like this:
Image
https://ibb.co/sm7ZJ4w

1. MSAA vs WinFormControl
Image Image
https://ibb.co/McksVvg https://ibb.co/pfrjZSN
Just like the picture above,
(1)the UI element (i.e. the menu item 'Edit_2') is recognized by Ranorex as:
- Flavor: msaa
- Caps: accessible
In my text I will call it 'MSAA UI element'

(2)the UI element (i.e. the button 'Save_2') is recognized by Ranorex as:
- Flavor: winforms
- Caps: control, nativewindow
In my text I will call it 'WinformControl UI element'


2. Good case (WinformControl UI element)
Now I use the button 'Save' to show a good case. The snapshots are in the attachment.
Before change, the properties of the button in Visual Studio is like this:
Image
https://ibb.co/09Kmfy6
From the picture we can see, there are 3 properties:
-AccessibleName: (empty)
-Text: Save
-(Name): button1
And then I changed its text to 'Save_2'. Now the 3 properties in Visual Studio like this:
Image
https://ibb.co/kJP201h
Now we can see the 3 properties are:
-AccessibleName: (empty)
-Text: Save_2
-(Name): button1

I have tested, even after the text change Ranorex can still recognize this button, because Ranorex take the property '(Name)' to create its XPath.
Element browser before change:
Image
https://ibb.co/QHGVxGT
Element browser after change:
Image
https://ibb.co/w45zt3d


3. Bad case (MSAA UI element)
Now I use the menu item 'Edit' to show a bad case. The snapshots are in the attachment.
Before change, the properties of the button in Visual Studio is like this:
Image
https://ibb.co/d0MF6Vx
From the picture we can see, there are 3 properties:
-AccessibleName: (empty)
-Text: Edit
-(Name): editToolStripMenuItem
And then I changed the text to 'Edit_2'. Now the 3 properties in Visual Studio like this:
Image
https://ibb.co/T1rC4Cr
Now we can see the 3 properties are:
-AccessibleName: (empty)
-Text: Edit_2
-(Name): editToolStripMenuItem

I have tested, after the text change Ranorex can not recognize this button, because Ranorex take the property 'Text' to create its XPath.
Element browser before change:
Image
https://ibb.co/DKV1tgn
Element browser after change:
Image
https://ibb.co/ZWjPJ3M
as we can see, the problem is Ranorex uses the property 'Text' but not 'Name' to as accessiblename. So when the text is changed, accessiblename / XPath is also changed, so Ranorex cannot find this UI element anymore. This problem is terrible. Because of this problem, I cannot test multi-language software, and I must change my problem after every text changes.

This is all my problem. I donnot know if some one has same problem like me? Or I make wrong settings? How can I go over this problem?


Lg
Rika
Attachments
Snapshots_AfterChange.rxsnp
(24.24 KiB) Downloaded 7 times
Snapshots_BeforeChange.rxsnp
(21.35 KiB) Downloaded 7 times

kOoO
Posts: 26
Joined: Wed Oct 17, 2018 11:15 am
Location: Zlin, CR

Re: UI elements cannot be identified correctly (Windows Form)

Post by kOoO » Tue Mar 02, 2021 2:09 pm

I see ...

I have tried the same and got the same results.
rx.png
rx.png (19.49 KiB) Viewed 241 times
I have set AccessibleName of the first two MenuItems manually in code and didn't touch the third one. In Ranorex, the first two MenuItems has the AccessibleName that I have set and the third one's AccessibleName is the default Text value. So either Ranorex or Visual Studio sets the AccessibleName to the initial Text value if not set differently

The "(Name)" property that you see in Visual Studio is defaultly a variable name in application code used to store the WinForm element ... so its main purpose is to be used internally ... but who knows why in some cases, the Name is exported and usable by Ranorex as property (for example for Text, Button, TreeView ... elements), but for msaa elements like MenuItems it is not ...

So until someone clarify this, you could maybe ask your developers to set the AccessibleName explicitly or find some other ways of selecting the menu items ... for example it could work nicely by selecting items by indexes, those are not often changed in menu and would work even in multilang app.

Rika L.
Posts: 17
Joined: Thu Nov 19, 2020 10:03 am

Re: UI elements cannot be identified correctly (Windows Form)

Post by Rika L. » Tue Mar 09, 2021 9:13 am

Hello kOoO,
thank you so much for your answer! I want to answer you on last friday, but the website of Ranorex was brokendown : )

This is so uncomfortable that Ranorex cannot get the property '(Name)' of UI elements. Because if I use AccessibleName als identification factors I must let the SW developers to add AccessibleName for all UI elements, this is almost impossible. It is also not stabile if I use index as identification factor, because the sequence changed sometime and only UI elements like Menu... can use index.
The software I tested is a very very complex software : (

But thank you very much kOoO! Thank you for your help.

Rika L.
Posts: 17
Joined: Thu Nov 19, 2020 10:03 am

Re: UI elements cannot be identified correctly (Windows Form)

Post by Rika L. » Tue Mar 23, 2021 7:59 pm

hello Ranorex support members,
do you have some ideas about my problem?
I really need an answer: )
This is very important problem for me.

Thank you
Rika