How to capture the currently selected gui element

Ask general questions here.
mgreco
Posts: 4
Joined: Mon Jul 10, 2017 5:01 pm

How to capture the currently selected gui element

Post by mgreco » Tue Nov 07, 2017 10:26 pm

I'm dealing with a purchased application that occassionally renders it's screen with two or more text fields named out of order. In this situation the input values captured in the text fields vary and cause the test case to fail. Is there any way to have the mouse or cursor be placed into a given text field and then call out via user code to get the currently selected item and subsequently the currently select item's text value?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to capture the currently selected gui element

Post by odklizec » Wed Nov 08, 2017 9:04 am

Hi,

I'm afraid, that without at very least Ranorex snapshot (NOT screenshot) of the problematic elements, there is not much anyone here can do or suggest. Also, please let us know your Ranorex version.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

mgreco
Posts: 4
Joined: Mon Jul 10, 2017 5:01 pm

Re: How to capture the currently selected gui element

Post by mgreco » Tue Nov 14, 2017 2:42 pm

I understand, thanks for the reply. I'm working on building the snapshot with another team member but wanted to try to explain the issue a bit more too, maybe this is an easy answer. The xpath is not an issue by the way, things are running fine more than 75% of the time I would say, it's the 25% where the screen elements are rearranged where we run into issues. Let me try to sketch this out with plain text, no images, etc.

Here's a simplified version of the screen in question with just two input boxes:
------------------------------------------
-- Label1: [ TextInputField1 ] -- (relative position 1 from top)
-- Label2: [ TextInputField2 ] -- (relative position 2 from top)
------------------------------------------

In the test case recording we capture the text value of TextInputField2 into a variable for later use in validation steps. This value always appears in relative position 2, and the labels never change. However, when we track the failures we see that TextInputField2 has now become TextInputField1. The value we need is now in TextInputField1 but the recording was originally created to capture the value from TextInputField2. I didn't write the app, so I can say it's sort of not the best written that's for sure, but it's input text boxes are changing names relative to the top.

The xpath for these two text box elements look like this (actual):

/form[@title~'^Oracle']/container[@name='OracleWindow']/container[@name='Main Body']/?/?/text[@name='textfield1']
/form[@title~'^Oracle']/container[@name='OracleWindow']/container[@name='Main Body']/?/?/text[@name='textfield2']

And again the recording captures the value in textfield2. But imagine now that the app renders relative position 2 with textfield1 25% of the time. I was crossing my fingers that I could place my cursor in the top input box, tab through to the 2nd box and then read the value without knowing the name of the box, or by getting the name of the box at runtime through user code.

Does this help? I'll still try to get you the snapshot (never did this before), but I'm not sure it will help in this case. This is the first time we've ran into this with this application. It's unfortunate that the developer created an app that dynamically generates it's widgets and then renders them in random order. But the labels and values are placed into these boxes in consistent order.

mgreco
Posts: 4
Joined: Mon Jul 10, 2017 5:01 pm

Re: How to capture the currently selected gui element

Post by mgreco » Tue Nov 14, 2017 2:49 pm

As a side note, we are experimenting with using the form element index value instead of the name of the field to capture what we need in element text value at element index value 4. This works so far since every even numbered index on the form is one of the text input boxes and we always need the 2nd input box value for validation purposes, 2nd being the 2nd box relative to the top of the form. This approach seems to be working for now, but it doesn't seem to be a permanent solution. But maybe it's all we can do for now...

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 3914
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to capture the currently selected gui element

Post by odklizec » Tue Nov 14, 2017 2:54 pm

Well, unless you find a way (snapshot would really help here) to make the xpath more precise (to find the right textfield), there is not much you can do about this. If there is, for example, a label describing the content of text field, this may help you to identify correct element relatively to label. But as mentioned, without at very least snapshot, there is not much anyone here can do or suggest. All I can say is you need to improve the xpath somehow.

BTW, indexes are definitely not best way of element identification. They should be used only as a last resort if there is really no other way to identify certain elements ;)
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration