Verify child nodes parent node in Tree

Experiences, small talk, and other automation gossip.
Rakesh123
Posts: 72
Joined: Thu Oct 28, 2010 2:18 pm

Verify child nodes parent node in Tree

Post by Rakesh123 » Sun Jul 15, 2012 3:51 am

Hi,

Actually the scenario is like this...

There is a tree control which have a parent node and have some childs under it.I need to verify all the child items in the parent node.

I am selecting the parent node through one of my method and then I am trying to verify the childrens under it. For this I wrote the following code but its not working..

public bool VerifyItem(string abc)

{

foreach(TreeItem items in Form.Tree.selectedItems)

{

if(items.decendentItems.text.contains(abc))

{

return true;

}

}

return false;

}


Please help in solving this ASAP

Thanks,

Rakesh

User avatar
artur_gadomski
Posts: 207
Joined: Mon Jul 19, 2010 6:55 am
Location: Copenhagen, Denmark
Contact:

Re: Verify child nodes parent node in Tree

Post by artur_gadomski » Mon Jul 16, 2012 8:21 am

Try replacing selectedItems with Items.

Rakesh123
Posts: 72
Joined: Thu Oct 28, 2010 2:18 pm

Re: Verify child nodes parent node in Tree

Post by Rakesh123 » Mon Jul 16, 2012 10:23 am

Hi,

I can do that but the thing is that I need to verify the child nodes of specific parent node because there is a chance that the same child nodes can be part of some other parent node but may be they are not present in the parent node which I want to verify

Thanks,
Rakesh

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

Re: Verify child nodes parent node in Tree

Post by Support Team » Mon Jul 16, 2012 11:52 am

Hi!

Do you have tried the two helpfull functions "FindChildren" and "FindDescendants" yet?
They give back a list of all child-nodes and descendant-nodes of type <T>, respectively.
So in your example it will look the following way...

foreach(TreeItem item in tree.FindChildren<TreeItem>())
{
Report.Info("Children",item.Text.ToString());
}

Regards,
Larissa
Ranorex Team

Rakesh123
Posts: 72
Joined: Thu Oct 28, 2010 2:18 pm

Re: Verify child nodes parent node in Tree

Post by Rakesh123 » Mon Jul 16, 2012 5:48 pm

Hi,

Yes both FindChildren & FindDecendents are very useful functions but my scenario is completely different.

The tree structure is like shown below

--A
--1
--2
--3
--B
--1
--2
--3
--C
--1
--2
--3


Here A,B,C are parent nodes and each have their childrens as '1,2,3'.
I need to verify all the childrens of parent Node "B".
Please provide me the solution for this ASAP.

Thanks,
Rakesh

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

Re: Verify child nodes parent node in Tree

Post by Ciege » Mon Jul 16, 2012 7:10 pm

Just root your FindChildren to the XPath of node B...
The last bit of code it rooted at the tree:
foreach(TreeItem item in tree.FindChildren<TreeItem>())

So change the the Tree.FindChildren to NodeBElement.FindChildren...
NOTE: NodeBElement is the element of your node B that you need to determine...
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...