Page 1 of 1

Using optional element

Posted: Thu Oct 16, 2014 9:15 am
by niteshr
Hi Guys,

I've worked on a project in the past and the UI has the following structure:

I set the domain via a variable at the top level. The example below is a textbox items XPath in the crrent repository.

/dom[@domain=$varDomain]//input[#'username']

So i'm working on a new project now and I want to use the same repository items. However, the difference in the UI is an IFrame. See below:

/dom[@caption='Page']//iframe[@id='iFrame']//input[#'username']

I am trying the following in Ranorex Spy to track the item on the new UI but it is not detecting. Please point me in the right direction. The below Xpath works on the old UI but not the new one:

/dom[@domain=$varDomain or @caption='Page']/?//input[#'username']

If I replace the question mark with the iframe[@id=@iFrame'] it detects the element. I thought the whole point of the ? was so it will be regaded as an optional element. Please help me asap. Thanks

Re: Using optional element

Posted: Thu Oct 16, 2014 11:32 am
by odklizec
Hi,

Try add the question mark after the iframe, like this...
iframe[@id=@iFrame']?

Re: Using optional element

Posted: Thu Oct 16, 2014 12:08 pm
by niteshr
No luck I'm afarid. The spy tool doesn't like that syntax. I'm trying to cut out referring to the IFrame as it doesn't exist in the first project. I changed the textbox's axis to descendant instead of child and I am able to highlight the element in the spy but when I run my test the element is not detected. Why would this be?

Re: Using optional element

Posted: Thu Oct 16, 2014 12:36 pm
by odklizec
OK, sorry, I was out of the PC and I thought it could be used like this. This one should work then ;)
iframe?[@id='iFrame']

So the whole path should be like this:
/dom[@domain=$varDomain or @caption='Page']//iframe?[@id='iFrame']//input[#'username']

Re: Using optional element

Posted: Thu Oct 16, 2014 2:16 pm
by niteshr
Thanks again. I need to exclude the IFrame though. I'm afraid this is a case of the spy detecting the element but the Ranorex studio can't. No idea how to solve this at the moment :(

Re: Using optional element

Posted: Mon Oct 20, 2014 1:46 pm
by Support Team
Hello guys,

I assume that the mentioned paths
  • "/dom[@domain=$varDomain]//input[#'username']"
    and
    "/dom[@caption='Page']//iframe[@id='iFrame']//input[#'username']"
uniquely identify the input element on the old and new UI, respectively.


Using the following path you should be able to find the element on both UIs:
  • /dom[@domain=$varDomain or @caption='Page']//input[#'username']
The .//input is the relative path identifying all input elements that are descendants of the current element. Depending on the structure of your application, this can be quite time-consuming.

If you are still facing issues, please contact [email protected]

Regards,
Robert

Re: Using optional element

Posted: Tue Nov 04, 2014 9:14 am
by niteshr
Thanks for that. Unfortunately, still no luck. I read in this post http://www.ranorex.com/forum/bug-unique ... t6173.html that an IFrame has a different scope from the dom. I'm assuming that is my issue. I have emailed the support team but got no feedback yet. I don't wan't to replicate my repository items and recordings. Please help me with an alternative solution

Re: Using optional element

Posted: Tue Nov 04, 2014 5:57 pm
by krstcs
niteshr,

Have you tried just adding "//iframe" in the middle of your path just to see if it will work?

/dom[@domain=$varDomain or @caption='Page']//iframe//input[#'username']


If it does work, then maybe that will fix the issue, it did for me.