Page 1 of 1

Getting the last child in an XPath

Posted: Tue Aug 16, 2011 6:37 pm
by Aracknid
Is there a fast way to get the last child in an Xpath?

For example, If I had something like this:

UL
|--- LI
|--- LI
|--- LI
|--- LI
|--- LI

And I wanted the get the last LI(but I don't know there are 5 of them), aside from getting a count of the children for the UL object and using the var in the xpath, can I do something else that is faster?

Say something like: objLI = objUL.FindSingle("./li[$]") (I use $ in my example because it means look at end for regular expression)

Thanks,

Aracknid

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:06 pm
by Ciege
Get an iList of all the LIs then get the information of the last one in the list...

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:08 pm
by Aracknid
Sorry, that was just a simple example I made up. I'm not actually looking for list items...

What I am looking for is the last child object within a DIV. I might be a Span, and Anchor, or possible something else.

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:16 pm
by Ciege
Does something like this work for you?

Code: Select all

IList<Ranorex.Unknown> AllMyChildren = MyRootElement.FindChildren<Ranorex.Unknown>(); 
Then get the last item in the AllMyChildren iList...

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:27 pm
by Aracknid
Nah, that doesn't do it for me :)

I'm just looking for a shorter way to do this:
objLI = objUL.FindSingle("./li[" & objUL.children.count & "]")
Hoping there is some sort of substitute for "objUL.children.count " that can be used instead.

Aracknid

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:49 pm
by Ciege
Hmmm, yet again I guess I don't have the right answer for you...
What is the reason why getting an iList of all the children objects of the root object then getting the last one from there does not work for you? In theory (in my mind) it should suffice...

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:54 pm
by Aracknid
I've already got a way to do it. I'm just lazy and hoping to type less. :)

Re: Getting the last child in an XPath

Posted: Tue Aug 16, 2011 7:56 pm
by Ciege
I'm just lazy and hoping to type less
Ha! A true test automation expert hard at work!!! :lol:
A man after my own heart....

Re: Getting the last child in an XPath

Posted: Wed Aug 17, 2011 8:56 am
by Support Team
Currently, there is no built-in function in RanoreXPath to specify the last element, but we have that feature on our roadmap together with a few other useful XPath operators that are currently not available in RanoreXPath.

Regards,
Alex
Ranorex Team