Getting value of last child element of a repository item

Ask general questions here.
Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Getting value of last child element of a repository item

Post by Martin » Thu Mar 05, 2015 2:10 pm

Hey

I've started work on automating our Sandbox testing (JSON flows).

And the issue on hand atm is that i have a response area where all the requests and responses are shown.
I need to get the InnerText of the last child element of the repository item that displays all this info.

Image

So the repository item will be the "Div'yui-log-bd' and in this case i will need the InnerText from the last child element aka "Div 'Application is not connected to the server.'. As info can be different the child elements name can also be different.

So the question is how can i achieve this with C#?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Getting value of last child element of a repository item

Post by Support Team » Fri Mar 06, 2015 10:15 am

Hi Martin,

In order to get the last element within this DIV tag you can use the following regular expression in your RanoreXPath

Starting from div[‘yui-log-bd’]

Code: Select all

/Div[@attribute=‘yui-log-bd’]/Div[last()=’true’]
It is also possible to combine the last()=’true’ with one of your attributes.
For example:

Code: Select all

/Div[@innertext>’Application’ and last()=’true’] //This path finds the last Div tag whereby the innertext starts with’Application’
Please find more information about Regular Expressions in combination with our RanorexPath in our User Guide.

Regards,
Markus (S)
.
Image

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: Getting value of last child element of a repository item

Post by Martin » Fri Mar 06, 2015 1:28 pm

Support Team wrote:Hi Martin,

In order to get the last element within this DIV tag you can use the following regular expression in your RanoreXPath

Starting from div[‘yui-log-bd’]

Code: Select all

/Div[@attribute=‘yui-log-bd’]/Div[last()=’true’]
It is also possible to combine the last()=’true’ with one of your attributes.
For example:

Code: Select all

/Div[@innertext>’Application’ and last()=’true’] //This path finds the last Div tag whereby the innertext starts with’Application’
Please find more information about Regular Expressions in combination with our RanorexPath in our User Guide.

Regards,
Markus (S)
Hey

Thank you for the reply. Got my last element.

Though for someone else who might have this issue i'd like to point out that "last()='True'" seems to actually be case sensitive. Didn't work with lowercase "t" in "True".

Martin
Posts: 152
Joined: Fri Aug 15, 2014 12:24 pm

Re: Getting value of last child element of a repository item

Post by Martin » Fri Mar 06, 2015 1:31 pm

But another question (I won't as of yet start a new topic for this):

It came out that some of the info i need might be nested even more in one of those nested Divs.

I have a functionality in my mind but i would like to know if there is a possibility to gather all "innerText"-s of all nested Divs in one main Div?

Example taking into account the picture in my first post.

Main Div: "yui-log-bd"
It has nested Divs: "Logger reset", "Web Socket connection..." etc
And these nested Divs might have even more nested Divs.

Is it possible to gather all the innerTexts of these nested Divs from my main Div (yui-log-bd)?

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Getting value of last child element of a repository item

Post by Support Team » Mon Mar 09, 2015 4:08 pm

Hi Martin,

RanoreXPath is based on W3C XPath. Therefore, you can use different Syntaxes to achieve your plan.
Please find some examples about the RanoreXPath in our User Guide.

Regards,
Markus (S)
.
Image