Page 1 of 1

Verifying an item in Tree

Posted: Sun Jul 10, 2011 3:59 pm
by Rakesh123
Hi frnds,
I am trying to verify an item is displayed correctly in the Tree object using the following code..

IList<Ranorex.TreeItem> treeitem=Form_Name.TreeOutLine_Name.FindChildren<Ranorex.TreeItem>();

foreach(TreeItem item in treeitem)
{
if(treeitem.text.Contains(item)
{
Report.Success("Item displayed in Tree");
}
else
{
Report.Failure("Item not found");
}
}

But this code is not working.

Below is the way the items are displayed..
-Item1
--Item2
I am trying to verify Item2 in the tree.Pls find the solution ASAP.

Thanks,
Rakesh

Re: Verifying an item in Tree

Posted: Mon Jul 11, 2011 10:01 am
by Support Team
Hi,

To me it is not clear what you are trying todo. Do you want to check if a text of a treeitem in your IList contains a specific string? Or do you want to do something else?
Rakesh123 wrote: I am trying to verify an item is displayed correctly in the Tree object using the following code..
The code you posted us cannot work. Is this the exact code you have in your Module? If you compile your code you will get a compiler error, because the IList has no property "Text".

Regards,
Peter
Ranorex Team

Re: Verifying an item in Tree

Posted: Tue Jul 12, 2011 5:58 pm
by Rakesh123
Yes,I want to verify whether a specific text is displayed as a part of any Treeitem in tree.

Re: Verifying an item in Tree

Posted: Wed Jul 13, 2011 10:10 am
by Support Team
Hi,

to check if a tree item ocurs in you tree you can use following method:
public bool findTreeItemInTree(Tree myTree, String itemName)
{
	IList<TreeItem> myItems = myTree.Find<TreeItem>(".//treeitem", 1000);
	foreach (TreeItem myItem in myItems)
	{
		if (myItem.Text == itemName)
			return true;
	}
	return false;
}
For more details about the code, please hava a look at our user guide/api documentation:
http://www.ranorex.com/support/user-gui ... xpath.html
http://www.ranorex.com/Documentation/Ra ... d__1_1.htm
http://www.ranorex.com/blog/ranorexpath-tips-and-tricks

Kind regards,
Tobias
Support Team