PxPath is different in different environments

Technology specific object identification, supported applications, web technologies, and 3rd party controls.
ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

PxPath is different in different environments

Post by ngrishakin » Mon Jul 17, 2017 8:05 pm

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: PxPath is different in different environments

Post by krstcs » Mon Jul 17, 2017 8:38 pm

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.
Shortcuts usually aren't...

ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

Re: PxPath is different in different environments

Post by ngrishakin » Mon Jul 17, 2017 9:13 pm

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

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

Re: PxPath is different in different environments

Post by odklizec » Tue Jul 18, 2017 6:52 am

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.
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

ngrishakin
Posts: 42
Joined: Fri Oct 04, 2013 9:47 pm

Re: PxPath is different in different environments

Post by ngrishakin » Tue Jul 18, 2017 4:03 pm

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

krstcs
Ranorex Guru
Posts: 2683
Joined: Tue Feb 07, 2012 4:14 pm
Location: Austin, Texas, USA

Re: PxPath is different in different environments

Post by krstcs » Tue Jul 18, 2017 5:00 pm

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.
Shortcuts usually aren't...