Page 1 of 1

Verify child nodes parent node in Tree

Posted: Sun Jul 15, 2012 3:51 am
by Rakesh123
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

Re: Verify child nodes parent node in Tree

Posted: Mon Jul 16, 2012 8:21 am
by artur_gadomski
Try replacing selectedItems with Items.

Re: Verify child nodes parent node in Tree

Posted: Mon Jul 16, 2012 10:23 am
by Rakesh123
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

Re: Verify child nodes parent node in Tree

Posted: Mon Jul 16, 2012 11:52 am
by Support Team
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

Re: Verify child nodes parent node in Tree

Posted: Mon Jul 16, 2012 5:48 pm
by Rakesh123
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

Re: Verify child nodes parent node in Tree

Posted: Mon Jul 16, 2012 7:10 pm
by Ciege
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...