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?
Finding dynamic elements
Re: Finding dynamic elements
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/
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 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
-
- Posts: 10
- Joined: Wed Oct 19, 2016 7:09 pm
Re: Finding dynamic elements
I have my snapshots. Where can I email them? I would like to keep them off the forum due to my company. Thanks.
Re: Finding dynamic elements
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
Edit by Support Team: Fixed email address

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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
-
- Posts: 10
- Joined: Wed Oct 19, 2016 7:09 pm
Re: Finding dynamic elements
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.
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Finding dynamic elements
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
Re: Finding dynamic elements
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 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
-
- Posts: 10
- Joined: Wed Oct 19, 2016 7:09 pm
Re: Finding dynamic elements
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 (6.55 KiB) Viewed 1120 times
-
- Posts: 254
- Joined: Tue Mar 24, 2015 5:05 pm
- Location: Des Moines, Iowa, USA
Re: Finding dynamic elements
Try something like this:
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.
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]
Doug Vaughan
Re: Finding dynamic elements
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.
Without a snapshot, it's like catching wind

Pavel Kudrys
Ranorex explorer at Descartes Systems
Please add these details to your questions:
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