Page 1 of 2

How to handle a dynamic pwf buttons ?

Posted: Sun Jun 19, 2016 10:16 am
by rastek
Can someone give me a proper way to handle this dynamic path ? For example for Start button I have a path which changes controlid numbers everytime.

/form[@title='FORENSIC Labs']/element[@controlid='50000']/element[@controlid='50037']//element[@controlid='50039']//element[@controlid='5179']/element[@controlid='56531']/element[@controlid='5229']/?/?/button[@text='Start']

I tried all standart ways mentioned in ranorex xpath regex page such as

./button
/form//button
.//button
../button
/form/?/button

for example /form[@title='FORENSIC Labs']//button[@text='Start'] doesn't work !

none of them works for me..Those elements before the button has static processName, I tried it but doesnt work either. Please help me a for working solution, thanks in advance.

Re: How to handle a dynamic pwf buttons ?

Posted: Mon Jun 20, 2016 7:56 am
by odklizec
Hi,

Unfortunately, it's pretty hard to suggest something reliable without Ranorex snapshot of the problematic element. Could you please publish one?

Basically, you will have to find different attributes to work with and maybe even change the xpath weight to prefer other attributes over "controlid" attribute, which is apparently not useful here. Automation of elements with dynamic IDs is very well described here:
http://www.ranorex.com/blog/automated-t ... namic-ids/

Re: How to handle a dynamic pwf buttons ?

Posted: Sun Oct 09, 2016 1:34 pm
by rastek
What I dont understand here is, when I use an attribute when identify an object, it should filter other attributes and only search with that right, so then why should I use weitghhing ? confused.

One more thing, I am using regex such as

/element[@controlid>'5] -> everytime id is 50000 or starts with 5, then why this regex does not work ? even if id does not changes ??

Re: How to handle a dynamic pwf buttons ?

Posted: Sun Oct 09, 2016 9:04 pm
by Support Team
rastek wrote:so then why should I use weitghhing ?
You can change the weight of attributes so they are used (or not used) automatically when tracking or recording.
rastek wrote:/element[@controlid>'5]
Could you please post the exact path you are using? The path you posted does not even use regex, nor is it a valid RanoreXPath.
A path that matches control IDs starting with "5" could be this one:

Code: Select all

/element[@controlid~'^5']
Regards,
Alex
Ranorex Team

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 20, 2016 5:43 pm
by rastek
Hi Alex,
here is full path

/form[@title='Blah blah Com']
element[@controlid='50000']/element[@controlid='50037']//element[@controlid='50039']//combobox[@controlid='6477']/text[@controlid='1001']

I already tried your suggestion, /element[@controlid~'^5'] not worked for me... Actually I tried everything in Ranorex regex page, not worked

And still did not get my question, according to that page it id always start with 5 it should work for >5, then why >5 is not working ?? Can you explain me that ? Is it becuse of weighthing, but it isnt only for recording ?

Let me explain myself, you say weithing is automatically when tracking or recording, but I already got xpath and know which is qunie only, id. weighthing is for recording, I have done my recording already.

What I want to say is that, is I play withing xpath, its same result weitghhing right ? I mean weitghhing chnages the xpath produced, but it does change anything on backgorund right ? Is there anything I missed ?

Re: How to handle a dynamic pwf buttons ?

Posted: Fri Oct 21, 2016 7:29 am
by odklizec
Hi,

Please upload a Ranorex snapshot of the element in question. It's really pretty hard (actually impossible) to suggest something reliable regarding the xpaths and xpath weights without at least seeing the snapshot!

ControlIDs are apparently not reliable to identify elements in your AUT. Therefore, you need to instruct Ranorex to create xpaths without controlids. And this is where xpath weighting is useful. But of course, you will also have to manually change/recreate all existing xpaths using contorlids (in repo).

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 6:29 am
by rastek
In my version , 5.3.2., I couldnt find snapshot feature ?

I already look at this page

http://www.ranorex.com/support/user-gui ... files.html

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 7:21 am
by odklizec
Hi,

At first, I'm pretty sure there is a "Save As Snapshot" functionality in 5.3.2 Spy. It's a standard Ranorex Spy feature, probably since the introduction of Spy or Snapshot functionality ;) Just open the Spy, track the element in question and then in Browser&Results section right click the found/tracked element. Then in the appeared popup menu select "Save As Snapshot".

At second, Ranorex 5.3.2 is a pretty old and no longer supported version! In 5.3.0, there was introduced a new native WPF plugin and since then, several following versions introduced number of bug fixes and enhancements related to WPF recognition. So I strongly recommend you to upgrade to latest 6.1.1! Even if there is a bug in your existing version, there is nothing Ranorex folks can do for you. Not to mention we are all wasting time suggesting solutions, which may not even work in your obsolete version. You see, all our suggestions and recommendations are based of LATEST available version! So please, try to solve your problem with latest Ranorex version. But in my humble opinion, your problem is not related to "obsolete" version. It's just that your GUI seems to have pretty dynamic IDs and so you need to use xpath weight to instruct Ranorex to generate xpaths with different attributes.

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 10:30 am
by rastek
Sory I didnt try with spy, I use 5.3 because we use Ranorex engine within another program only with supported versions, but also I use standalone.

I have recorded and played success wpf applications with even older versions than 5.3, Ranorex support that technology for a long time, my problem is to make it generic so that it works every time.

I will send the snapshot, thanks.

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 11:50 am
by odklizec
Yes, I understand. And this this why you have to adapt the xpath weight because control IDs in your app appear to be completely useless (random). However, you will have to adapt/recreate also the existing xpaths in repo, because changed xpath weight will affect only newly created xpaths. I'm afraid, there is no other way.

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 12:39 pm
by rastek
Taking new recording not a problem, I do not have much repository recordings since couldnt get it work.

I attached the file, its a little bit confusing there are many buttons seen

My problem is not because they are random, even if I say start with 5, and it start with 5 it doesnt find objects ??

I still confused at some point and will ask same question, weighthing effect something in the background ? you say "changed xpath weight will affect only newly created xpaths." so If I change xpaths manually and remove controlids write some other xpath (that weighthing will for me ), is it same thing or not ? chnage weigthing only change xpaths ?

Re: How to handle a dynamic pwf buttons ?

Posted: Thu Oct 27, 2016 1:21 pm
by odklizec
Thanks for the snapshot. Now please post an example xpath, which fails and which you believe Ranorex should find in the snapshot.

The only thing Ranorex xpath weight changes is the priority of elements Ranorex picks during recording/tracking. For example, this is the xpath obtained from the spy with default xpath weight:

Code: Select all

/form[@title='GENBAND GENCom']/element[@controlid='50000']/element[@controlid='50037']/element/element[@controlid='50038']/element[@controlid='50039']/element[@controlid='6501']/element[@controlid='6473']/button[@text='Cancel']
Now the ControlID is typically considered a very good attribute for creating xpaths. Hence it has a very high xpath weight priority. However, in some GUIs (like yours) ControlIDs is "random" and the numbers inside could change with each single build of your application. So it's better to avoid them completely from the process of xpath creation. And this can be done by lowering the ControlID weight or by increasing weight number of another attribute, which gives that "another" attribute a higher priority.

There is a very good blog post about testing GUI with dynamic IDs with several examples how to use xpath weight:
http://www.ranorex.com/blog/automated-t ... namic-ids/

However, since your interface does not have very nice ControlIDs and there is not much other attributes that could be used, I would suggest to simply try to reduce the xpath to bare minimum, like this:
/form[@title='GENBAND GENCom']//element/button[@text='Cancel']
Of course, such xpath reduction could always result to increased search time, so it must be used with caution ;)

Re: How to handle a dynamic pwf buttons ?

Posted: Sat Oct 29, 2016 10:42 pm
by rastek
Thanks odlkizec, that helped me :) Can you also give path for the end button I send in.

I made a similar path as you send for the end button but below statement didnt helped me. Actually I tried similar things before by eliminating ids but could find exact paths, I tried man permutations as below but didnt work..

/form[@title='GENBAND GENCom']//element/button[@text='End Call']
/form[@title='GENBAND GENCom']//element/?/?/button[@text='End Call']

Here is the full path for Cancel,End and Conference buttons, the difference is; latest one has more control ids between form and the button. I tried to add /?/?/ before button statement but didnt worked. Can you please help me for those buttons also ?

element[@controlid='50000']/element[@controlid='50037']//element[@controlid='50039']//button[@text='Cancel']

element[@controlid='50000']/element[@controlid='50037']//element[@controlid='50039']//element[@controlid='5179']/element[@controlid='50439']/element[@controlid='5229']/?/?/button[@text='End Call']

element[@controlid='50000']/element[@controlid='50037']//element[@controlid='50039']//element[@controlid='5179']/element[@controlid='50622']/element[@controlid='5229']/?/?/button[@text='Conference']

Re: How to handle a dynamic pwf buttons ?

Posted: Mon Oct 31, 2016 9:06 am
by odklizec
Hi,

You must be very careful about simplifying the xpath! If you simplify the xpath too much, Ranorex may not find the exact element you intended to be found. For example, there are three 'End Call' buttons in your GUI! And the xpath
/form[@title='GENBAND GENCom']//element/?/?/button[@text='End Call']
finds all of them, because of /?/?/ section of xpath, which means, this part of xpath is optional!
So the result is like this:
EndCall_BTN.png
And if there is found more than just one element by the xpath, Ranorex ALWAYS uses the first one, which may not necessarily be the correct one ;)

I've examined these three buttons and found some differences, which could be used to make the xpath more precise and reliable. For example, two of the three buttons contains "accessibledefaultaction" attribute and the button you want to 'find' has an "Instance" value '0'. So the xpath for 'End Call' should look like this:
/form[@title='GENBAND GENCom']//element/button[@text='End Call' and @accessibledefaultaction='Press' and @Instance='0']
As for the Conference button, there seems to be just one button like this, so it should be safe to use xpath like this:
/form[@title='GENBAND GENCom']//element/button[@text='Conference']
.
Hope this helps? ;)

Re: How to handle a dynamic pwf buttons ?

Posted: Mon Oct 31, 2016 6:11 pm
by rastek
Thanks odklizec,

Both of them not working :(
Actually I know multi object issue, I use [1] or [2] at the end in scenarios where it is working.

and for End button for example, normaly this should work

/form[@title='GENBAND GENCom']//element/button[@text='End Call'][1] or [2] etc

But I think there is wproblem with /?/? section.

for the second one,
/form[@title='GENBAND GENCom']//element/button[@text='Conference'] is not working, I already tried it before.

What can you else suggest ?