Finding dynamic elements

Ask general questions here.
mzydorczyk
Posts: 10
Joined: Wed Oct 19, 2016 7:09 pm

Finding dynamic elements

Post by mzydorczyk » Thu Jun 15, 2017 6:55 am

Hi. In my application Ranorex is able to find an element that is in question. I have it in the repo and when I highlight the element it highlights. All good there.

Now this is where it gets tricky. The element is in a "navigation tree" that can be refreshed. When this refresh happens, the objects in the tree are rebuilt (behind the scenes). The problem I'm having is that at the start of the test Ranorex knows where the element is. During the test I click the refresh button in the app. Then at the end of the test I validate that the element still exists but Ranorex seems to have lost where the element is because that instance of the element that existed at the start is no longer there even though the element really is there.

I have caching of the elements turned off so is there any way Ranorex can re-search for the element at the time my validation module runs without holding onto that old instance of the element?

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

Re: Finding dynamic elements

Post by odklizec » Thu Jun 15, 2017 7:15 am

Hi,

Could you please post a Ranorex snapshot of the problematic element? Ideally, post two snapshots...before and after the refresh. Also, please post an xpath of the element, as stored in repo. This would help us to understand your problem and offer best strategy to overcome the problem.

Additionally, I would suggest to check this blog post about working with dynamic IDs...
https://www.ranorex.com/blog/automated- ... namic-ids/
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

mzydorczyk
Posts: 10
Joined: Wed Oct 19, 2016 7:09 pm

Re: Finding dynamic elements

Post by mzydorczyk » Thu Jun 15, 2017 1:07 pm

I have my snapshots. Where can I email them? I would like to keep them off the forum due to my company. Thanks.

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

Re: Finding dynamic elements

Post by odklizec » Thu Jun 15, 2017 1:37 pm

Well, you can either send the snapshot(s) to [email protected] (with link to this discussion). This email is handled directly by Ranorex folks. Or you can send it to me, via private message. Please don't forget about the xpath used in repo.


Edit by Support Team: Fixed email address ;)
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

mzydorczyk
Posts: 10
Joined: Wed Oct 19, 2016 7:09 pm

Re: Finding dynamic elements

Post by mzydorczyk » Thu Jun 15, 2017 2:23 pm

My company does pay for the premium support so I put all my stuff together and sent to them which doesn't really help you. However, in regard to your link you gave me about dynamic elements, it mentioned if an element is identified by "id". What if my element isn't identified by id? I'm just identifying a treeitem by its text. Even when I look at all the properties in spy I don't even see an id property.

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Finding dynamic elements

Post by Vaughan.Douglas » Thu Jun 15, 2017 2:44 pm

mzydorczyk wrote:My company does pay for the premium support so I put all my stuff together and sent to them which doesn't really help you. However, in regard to your link you gave me about dynamic elements, it mentioned if an element is identified by "id". What if my element isn't identified by id? I'm just identifying a treeitem by its text. Even when I look at all the properties in spy I don't even see an id property.

If you're identifying the element by text and the text doesn't change, you shouldn't be seeing the problem you're describing. Is there maybe an element upstream that has changed?
Doug Vaughan

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

Re: Finding dynamic elements

Post by odklizec » Thu Jun 15, 2017 3:00 pm

My guess is that there are some element indexes used in the xpath, which change with each reload? But without seeing the xpath and snapshot (and actual error message), it's impossible to tell what's wrong.
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

mzydorczyk
Posts: 10
Joined: Wed Oct 19, 2016 7:09 pm

Re: Finding dynamic elements

Post by mzydorczyk » Thu Jun 15, 2017 3:34 pm

How can I get the xpath after the refresh? I would need to retrack the element wouldn't I? That's what makes this complicated. The path is not changing. This is the path before and after (after retracking each time). Unless I'm missing something, those are the same. If I refresh the tree in the app and click away from the element in the "browser & results" tab in spy then click back on it I get "{DisconnectedItem}" (see screenshot). The "disconnecteditem" is the real "after" path. No indexes should be changing either I assume. I mean if they did it would reflect in the path correct?

Code: Select all

/form[@automationid='ControlCenterWindow' and @wpfnative='True' and @name='ControlCenterWindow']/element[pos()=0]/element[pos()=0]/element[pos()=0]/container[pos()=0]/container[pos()=3]/container[pos()=2]/element[pos()=2]/element[pos()=0]/container[pos()=0]/element[pos()=0]/element[pos()=0]/container[pos()=0]/container[@automationid='SearchableTree' and @name='SearchableTree']/element[pos()=0]/element[pos()=0]/container[@automationid='SearchableTreeMainGrid' and @name='SearchableTreeMainGrid']/tree[@automationid='SearchableTree_Tree' and @name='Tree']/element[@automationid='Bd' and @name='Bd']/container[@automationid='_tv_scrollviewer_' and @name='_tv_scrollviewer_']/container[pos()=0]/element[pos()=5]/element[pos()=0]/container[pos()=0]/treeitem[@automationid='SearchableTree_TreeViewItem' and @text='Searches']/container[pos()=0]/element[@automationid='SearchableTree_TreeViewItem_ItemsPresenter' and @name='Items']/container[pos()=0]/treeitem[@automationid='SearchableTree_TreeViewItem' and @text='NewSearchFolder']/container[pos()=0]

Code: Select all

/form[@automationid='ControlCenterWindow' and @wpfnative='True' and @name='ControlCenterWindow']/element[pos()=0]/element[pos()=0]/element[pos()=0]/container[pos()=0]/container[pos()=3]/container[pos()=2]/element[pos()=2]/element[pos()=0]/container[pos()=0]/element[pos()=0]/element[pos()=0]/container[pos()=0]/container[@automationid='SearchableTree' and @name='SearchableTree']/element[pos()=0]/element[pos()=0]/container[@automationid='SearchableTreeMainGrid' and @name='SearchableTreeMainGrid']/tree[@automationid='SearchableTree_Tree' and @name='Tree']/element[@automationid='Bd' and @name='Bd']/container[@automationid='_tv_scrollviewer_' and @name='_tv_scrollviewer_']/container[pos()=0]/element[pos()=5]/element[pos()=0]/container[pos()=0]/treeitem[@automationid='SearchableTree_TreeViewItem' and @text='Searches']/container[pos()=0]/element[@automationid='SearchableTree_TreeViewItem_ItemsPresenter' and @name='Items']/container[pos()=0]/treeitem[@automationid='SearchableTree_TreeViewItem' and @text='NewSearchFolder']/container[pos()=0]
Attachments
2017-06-15_1030.png
2017-06-15_1030.png (6.55 KiB) Viewed 507 times

Vaughan.Douglas
Posts: 250
Joined: Tue Mar 24, 2015 5:05 pm
Location: Des Moines, Iowa, USA

Re: Finding dynamic elements

Post by Vaughan.Douglas » Thu Jun 15, 2017 3:57 pm

Try something like this:

Code: Select all

/form[@automationid='ControlCenterWindow' and @wpfnative='True' and @name='ControlCenterWindow']//container[@automationid='SearchableTree' and @name='SearchableTree']//container[@automationid='SearchableTreeMainGrid' and @name='SearchableTreeMainGrid']/tree[@automationid='SearchableTree_Tree' and @name='Tree']/element[@automationid='Bd' and @name='Bd']/container[@automationid='_tv_scrollviewer_' and @name='_tv_scrollviewer_']//treeitem[@automationid='SearchableTree_TreeViewItem' and @text='Searches']//element[@automationid='SearchableTree_TreeViewItem_ItemsPresenter' and @name='Items']//treeitem[@automationid='SearchableTree_TreeViewItem' and @text='NewSearchFolder']/container[pos()=0]
This can be further reduced using axes, but without a snapshot it's more of a shot in the dark I'd take at this point.
Doug Vaughan

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

Re: Finding dynamic elements

Post by odklizec » Fri Jun 16, 2017 7:23 am

Agree with Vaughan,

Without a snapshot, it's like catching wind ;) Anyway, all these containers and element with "Pos" function are pretty fragile and most probable reason of your problems. Using Pos function is more or less the same as using indexes. As suggested by Vaughan, I would try to simplify the xpath and eliminate all elements with indexes and pos functions. Not all elements in the xpath are really necessary to be there. Or at least replace them (indexes) with something more sensible.
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