RxPath changing in runtime

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

RxPath changing in runtime

Post by WajdaW » Mon Apr 09, 2012 11:25 am

Hi,

I'm running win 7 as administrator, with UAC off. I run my tests in single separate process in Nunit.

Here is scenario:

I have some dialog which contains beside other controls two buttons, 'Link' and 'Cancel'.
When I click on 'Link' button some message box appears. When I close message box I try to click on 'Cancel' but my button cannot be found. But when I try to click on "Cancel' without clicking on 'Link' and hence not showing message box, my 'Cancel' button can be found.

I though it might be something with cache option in repository, I turned off caching, but problem was still here.

Than I tried to change my path to 'Cancel' button and I was able to find it.

But the problem is that I'll need to have 2 RxPaths for same button depending on whether message box has been shown or not, which is pretty unuseful.

Path before message box is shown is: element[@controlName='cancelButton']/button
And after message box is shown is: button[@controlName='cancelButton']

More info, I tried to search for path using Ranorex Spy in both situations, but Ranorex Spy always returns same path, this one: element[@controlName='cancelButton']/button
So by ranorex spy I was able to find element even after message box appearing, but through automation API I wasn't able.

Why is this happening? How can I solve it?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: RxPath changing in runtime

Post by Support Team » Tue Apr 10, 2012 9:47 am

Hi,

WajdaW wrote:Path before message box is shown is: element[@controlName='cancelButton']/button
And after message box is shown is: button[@controlName='cancelButton']
Basically the follwoing RanoreXPath will fit both scenarios:

Code: Select all

//*[@controlName='cancelButton']
For further information about the RanoreXPath please have a look at follwoign chapters of our user guide:
RanoreXPath
RanoreXPath Editor
RanoreXPath - tips and tricks

Regards,
Tobias
Ranorex Team

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: RxPath changing in runtime

Post by WajdaW » Tue Apr 10, 2012 2:02 pm

Code: Select all

//*[@controlName='cancelButton']
How should I cast this element to button adapter since once it can be Element with child element of type Button, and once can be Button?

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: RxPath changing in runtime

Post by Support Team » Tue Apr 10, 2012 2:18 pm

Hi,

basically you can also use the RanoreXPath:

Code: Select all

element[@controlName='cancelButton']
which will also work for both scenarios, as a button is always an element too.

Regards,
Tobias

WajdaW
Posts: 75
Joined: Wed Jan 05, 2011 6:45 pm

Re: RxPath changing in runtime

Post by WajdaW » Tue Apr 10, 2012 5:16 pm

Thanks Tobias, I used /*[@controlname='cancelButton'] path.
And than I checked in runtime whether element is Button or not, if not than I used it's child.

That solved problem.

Best regards,
Vladimir

ColinO
Posts: 2
Joined: Tue Jul 17, 2012 4:10 pm

Re: RxPath changing in runtime

Post by ColinO » Tue Jul 17, 2012 10:41 pm

Hi there,

It looks like I have a very similar problem to that discussed in this thread. My Ranorex Spy goes from recognizing /container and /text element to generalizing them both to elements and appending a new /text element onto the path as shown below.

My initial ranorex path that worked the previous 2 days:
1)

Code: Select all

"/form[@controlname='formBarcodeProcess']/container/text[@controlname='txtFileNamePrefix']"
My ranorex path that worked this morning:
2)

Code: Select all

"/form[@controlname='formBarcodeProcess']/element[@controlname='grpBinderInfo']/element[@controlname='txtFileNamePrefix']/text[@accessiblename='Attachment Name:']"
And a couple of hours later:
3)

Code: Select all

"/form[@controlname='formBarcodeProcess']/container/text[@controlname='txtFileNamePrefix']
/text[@accessiblename='Attachment Name:']"
10 minutes later, the path reverted back to code snippet #2.

Just to note, I'm using .Net 4.0 on a 64-bit machine and the problem only seems to occur when the application we're testing is closed and re-opened. I'm wondering if the path name inconsistency has to do with some setting that I am unaware of?

Or maybe I can solve the problem like the original poster did.
I'm thinking of changing the path to the following "//element[@controlname='txtFileNamePrefix']".

ColinO
Posts: 2
Joined: Tue Jul 17, 2012 4:10 pm

Re: RxPath changing in runtime

Post by ColinO » Wed Jul 18, 2012 2:54 pm

For anyone else wondering what the original poster's solution code is for checking if that element (or its child) is of the desired type, here's some sample code of how I think it's done:

Code: Select all

Ranorex.Text textArea;
Ranorex.Core.Element textElement;
if(Host.Local.TryFindSingle("element path name here", 2000, out textElement)
{
     if( textElement.As<Text>() != null )
     {
            //the element is of type text.
            textArea = textElement.As<Text>();
     }
     else if( textElement.Children[0].As<Text>() != null)
     {
            //the child is your text element.
            textArea = textElement.Children[0].As<Text>();
     }
}
When I came back to my machine this morning all my original paths from code snippet #1 were working again... So temporarily I'm all set, though I'm sure it will be short lived.

User avatar
Support Team
Site Admin
Site Admin
Posts: 12145
Joined: Fri Jul 07, 2006 4:30 pm
Location: Houston, Texas, USA
Contact:

Re: RxPath changing in runtime

Post by Support Team » Thu Jul 19, 2012 11:41 am

Hi,
I'm wondering if the path name inconsistency has to do with some setting that I am unaware of?
Usually the path should always be built the same way. If the problem occurs again, please make snapshots
(http://www.ranorex.com/support/user-gui ... files.html),
so we can help you to figure things out.


Or maybe I can solve the problem like the original poster did.
I'm thinking of changing the path to the following "//element[@controlname='txtFileNamePrefix']".
'//' will work of sure.
Another helpful adapter (next to the ' * ' adapter) would be the 'optional' adapter ' ? ', since in snippet 1 and 3 your element is wrapped in a container and in snippet 2 it isn't.
With this adapter it is possible to mark some parts of a path as optional which means that the referred elements can be found even if optional parts of the path do not exist (e.g. container).

Kind regards,
Larissa
Ranorex Support Team