Page 1 of 1

PxPath is different in different environments

Posted: Mon Jul 17, 2017 8:05 pm
by ngrishakin
Hello! I'm running automation in Test and UAT environments. I'm using Ranorex as a library for my NUnit C# test project. And I have the following accessor methods in one of my object repository:

Code: Select all

        public WebElement FirstNameAfterClick => NewContactPage.FindSingle(
            ".//iframe[#'contentIFrame0']//input[#'firstname_i']", Global.WaitTime);

        public WebElement LastNameAfterClick => NewContactPage.FindSingle(
            ".//iframe[#'contentIFrame1']//input[#'lastname_i']", Global.WaitTime);
This is a CRM application and it has iFrames in it. In one environment RxPath can be
".//iframe[#'contentIFrame0']" in another ".//iframe[#'contentIFrame1']".
I can probably use TryFindSingle() function to check if path exists or not and then use Frame1 or Frame0 but it's too much code. I wonder if I can use Regex or wild card instead of 1 or 0 in IFrame name?
Thanks a lot,
Nik

Re: PxPath is different in different environments

Posted: Mon Jul 17, 2017 8:38 pm
by krstcs
You absolutely can (and probably should) use regex.

I would suggest something like this:

.//iframe[@id~'.*contentIFrame.*']//input[#'lastname_i']

This assumes that the iframe's id will always have 'contentIFrame' in it somewhere.

Note that @id='xyz' is the same as #'xyz', except that # tells Ranorex to expect a globally unique id, which it can hash, making finding it faster. @id= will (generally, depending on the rest of the path) return the exact same element, but it might take slightly longer.

Since you have an iframe, you still have to explicitly declare it in the xpath (unfortunately!!) or you would be able to just go down to the input tag element by itself, and it would be just as fast, since it has a unique id.

Re: PxPath is different in different environments

Posted: Mon Jul 17, 2017 9:13 pm
by ngrishakin
I noticed that your solution is working but slow. Below is HTML with first name input text box.

Code: Select all

<input title="" class="ms-crm-InlineInput" id="firstname_i" aria-labelledby="firstname_c firstname_w" style="-ms-ime-mode: active;" type="text" maxlength="100" attrName="firstname" attrPriv="7" controlmode="normal">
How can I use id name in your RxPath expression?
Thanks a lot for all your help,
Nik

Re: PxPath is different in different environments

Posted: Tue Jul 18, 2017 6:52 am
by odklizec
Hi,

Please post a Ranorex snapshot (not screenshot!) of the problematic element. You see, it would be much easier to help you with available Ranorex snapshot. With snapshot, we can learn and better understand the structure of your AUT and eventually provide a better answer ;)

As for your last question, regarding usage of id="firstname_i" in the xpath, it should be possible to use it the same as lastname_i in previously suggested xpath...

Code: Select all

.//iframe[@id~'.*contentIFrame.*']//input[#'firstname_i']
As for the reason why the above xpath is slow, it's becasue the first/lastname_i element is searched in all "contentIFrame" iframes. So if there is a lot of "contentIFrame" iframes in the AUT, it may take some time. The only way around is to use unique/more precise xpath.

Re: PxPath is different in different environments

Posted: Tue Jul 18, 2017 4:03 pm
by ngrishakin
Thank you Pavel. Unfortunately I'm not using Rx IDE and cannot provide "Ranorex snapshot".
Please correct me if I'm mistaken. Can I get a snapshot just with Spy?
Thanks,
Nik

Re: PxPath is different in different environments

Posted: Tue Jul 18, 2017 5:00 pm
by krstcs
First, yes, you can save a snapshot from Ranorex Spy.

Second, since you have a professional license, you can always open up the IDE and use the tools, even if you don't use it for creating the tests.