Verifying an item in Tree

Class library usage, coding and language questions.
Rakesh123
Posts: 63
Joined: Thu Oct 28, 2010 2:18 pm

Verifying an item in Tree

Post by Rakesh123 » Sun Jul 10, 2011 3:59 pm

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

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Verifying an item in Tree

Post by Support Team » Mon Jul 11, 2011 10:01 am

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
.
Image

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

Re: Verifying an item in Tree

Post by Rakesh123 » Tue Jul 12, 2011 5:58 pm

Yes,I want to verify whether a specific text is displayed as a part of any Treeitem in tree.

User avatar
Support Team
Site Admin
Site Admin
Posts: 11709
Joined: Fri Jul 07, 2006 4:30 pm
Location: Graz, Austria

Re: Verifying an item in Tree

Post by Support Team » Wed Jul 13, 2011 10:10 am

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
.
Image