Getting the last child in an XPath

Ask general questions here.
User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Getting the last child in an XPath

Post by Aracknid » Tue Aug 16, 2011 6:37 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Getting the last child in an XPath

Post by Ciege » Tue Aug 16, 2011 7:06 pm

Get an iList of all the LIs then get the information of the last one in the list...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Getting the last child in an XPath

Post by Aracknid » Tue Aug 16, 2011 7:08 pm

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.

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Getting the last child in an XPath

Post by Ciege » Tue Aug 16, 2011 7:16 pm

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...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Getting the last child in an XPath

Post by Aracknid » Tue Aug 16, 2011 7:27 pm

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

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Getting the last child in an XPath

Post by Ciege » Tue Aug 16, 2011 7:49 pm

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...
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

User avatar
Aracknid
Posts: 388
Joined: Tue Aug 10, 2010 3:23 pm
Location: Toronto, Ontario, Canada

Re: Getting the last child in an XPath

Post by Aracknid » Tue Aug 16, 2011 7:54 pm

I've already got a way to do it. I'm just lazy and hoping to type less. :)

User avatar
Ciege
Posts: 1336
Joined: Thu Oct 16, 2008 6:46 pm
Location: Arizona, USA

Re: Getting the last child in an XPath

Post by Ciege » Tue Aug 16, 2011 7:56 pm

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....
If this or any response has helped you, please reply to the thread stating that it worked so other people with a similar issue will know how you fixed your issue!

Ciege...

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

Re: Getting the last child in an XPath

Post by Support Team » Wed Aug 17, 2011 8:56 am

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