Page 1 of 1

How to get second child

Posted: Wed Oct 02, 2019 7:45 pm
by IvanT
Hi. how to get second specific child. now i am doing this from user code like this:
Host.Local.Find<RawText>("/form[@controlname='MainForm']//tree[@controlname='ObjTree']/rawtext[@rawtext='1_01_19']")[1]
how can i do this in repository?

Re: How to get second child

Posted: Wed Oct 02, 2019 8:54 pm
by odklizec
Hi,

Please upload a Ranorex snapshot (NOT screenshot) of the tree element, so people here at forum can analyse it a suggest best approach. Thanks.

Re: How to get second child

Posted: Thu Oct 03, 2019 4:56 pm
by IvanT
here it is

Re: How to get second child

Posted: Fri Oct 04, 2019 7:27 am
by odklizec
Hi,

Thanks for the snapshot. At first, the xpath you are using in code, does not correspond with the snapshot you posted. It seems that there is no ControlName attribute, either for form and tree element. Just 'name', so the path should look like this:

Code: Select all

/form[@name='MainForm']//tree[@name='ObjTree']/rawtext[@rawtext='1_01_19']
And unless I'm not missing something, this is also the xpath you can use in repo. Or do you want to find something else?

BTW, you don't have to use rawtexts, because the tree element, with all its elements and entire hierarchy, is available as standard tree element...
TreeElement.png
So the xapth with tree element, instead of rawtext, looks like this:

Code: Select all

/form[@name='MainForm']//tree[@name='ObjTree']//treeitem[@name='1_01_19']

Re: How to get second child

Posted: Sat Oct 05, 2019 10:22 am
by IvanT
I need Rawtext because treeitem has a big picture and I need to click on the text exactly

Re: How to get second child

Posted: Tue Oct 08, 2019 8:34 am
by odklizec
Hi,

So the xpath I provided (to RawText) worked for you?

Re: How to get second child

Posted: Tue Oct 08, 2019 8:57 pm
by IvanT
Hi. if you try to find element with your rxpath in my snapshot you will find two elements. but i need only second

Re: How to get second child

Posted: Tue Oct 08, 2019 9:08 pm
by Support Team
Hi IvanT,

Try adding a [2] at the end of the RxPath (this will select the [N] returned element).

Cheers,
Ned