How to get second child

Best practices, code snippets for common functionality, examples, and guidelines.
IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

How to get second child

Post by IvanT » Wed Oct 02, 2019 7:45 pm

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?

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get second child

Post by odklizec » Wed Oct 02, 2019 8:54 pm

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.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

Re: How to get second child

Post by IvanT » Thu Oct 03, 2019 4:56 pm

here it is
You do not have the required permissions to view the files attached to this post.

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get second child

Post by odklizec » Fri Oct 04, 2019 7:27 am

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']
You do not have the required permissions to view the files attached to this post.
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

Re: How to get second child

Post by IvanT » Sat Oct 05, 2019 10:22 am

I need Rawtext because treeitem has a big picture and I need to click on the text exactly

User avatar
odklizec
Ranorex Guru
Ranorex Guru
Posts: 7470
Joined: Mon Aug 13, 2012 9:54 am
Location: Zilina, Slovakia

Re: How to get second child

Post by odklizec » Tue Oct 08, 2019 8:34 am

Hi,

So the xpath I provided (to RawText) worked for you?
Pavel Kudrys
Ranorex explorer at Descartes Systems

Please add these details to your questions:
  • Ranorex Snapshot. Learn how to create one >here<
  • Ranorex xPath of problematic element(s)
  • Ranorex version
  • OS version
  • HW configuration

IvanT
Posts: 51
Joined: Wed Feb 06, 2019 8:00 pm

Re: How to get second child

Post by IvanT » Tue Oct 08, 2019 8:57 pm

Hi. if you try to find element with your rxpath in my snapshot you will find two elements. but i need only second

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

Re: How to get second child

Post by Support Team » Tue Oct 08, 2019 9:08 pm

Hi IvanT,

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

Cheers,
Ned