Iterating through Tree and open subtrees dynamically

Ask general questions here.
riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Iterating through Tree and open subtrees dynamically

Post by riccardo » Mon Oct 03, 2011 2:02 pm

I followed the instruction to iterate through a tree and click on each element in the tree. This does work fine if all TreeItems (and Sub Items) are expanded. As soon as I need to expand a TreeItem the items below won't be handled. This is how what I have coded so far:

Code: Select all

        public void ExtractTree()
        {
            //Report.Log(ReportLevel.Info, "Mouse", "Mouse Left Click item 'FormA.Workstations.TreeItemWorkstations' at Center.", repo.FormA.Workstations.TreeItemWorkstationsInfo, new RecordItemIndex(-1));
            if (! repo.FormA.Workstations.TreeItemWorkstations.Expanded){
            	repo.FormA.TreeItemWorkstations.DoubleClick();
            }
                  
            foreach (TreeItem item in repo.FormA.Workstations.TreeItemWorkstations.Items)
            {            	
            	IterateTree(item);
            }
            
        }
        
        /// <summary>
        /// Iterate Tree
        /// </summary>
        /// <param name="treeItem"></param>
        public static void IterateTree(TreeItem treeItem)
        {
        	
        	// Expand Tree Item if necessary
        	if (! treeItem.Expanded)
        	{
        		treeItem.DoubleClick();
        	}
        	
        	// Loop through Items
        	foreach (TreeItem item in treeItem.Items)
        	{
        		// Click Tree Item
        		if (! treeItem.Expanded) {
        			treeItem.DoubleClick();
        		}
        		
        		IList<TreeItem> myItems = item.FindChildren<TreeItem>();
        		
        		foreach (TreeItem myItem in myItems)
        		{
        			IterateTree(myItem);
        		}
        		
        		// Click Tree Item
        		item.DoubleClick();
        		
        	}
        }

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

Re: Iterating through Tree and open subtrees dynamically

Post by Ciege » Mon Oct 03, 2011 4:04 pm

It could be that the sub tree items don't exist until the parent is expanded. Since you are getting you list of tree items before the expand then the sub items will not exist in your tree items variable.
You can process the tree by expanding all the sub trees first, then getting the list of available tree items.

With many trees you can click in the first parent node and type - to close all sub items, and/or + or * to expand all tree items. You may be able to use invokeremotely to invoke the expand all action to expand all the tree items, then you can get your list and parse them.
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...

riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Re: Iterating through Tree and open subtrees dynamically

Post by riccardo » Mon Oct 03, 2011 4:11 pm

That would mean I need two routines, one which opens all the items, the second one which does the iteration, right?

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

Re: Iterating through Tree and open subtrees dynamically

Post by Ciege » Mon Oct 03, 2011 4:17 pm

It can all be in one method but yes, this would be a multiple step process. One step to verify the tree is fully expanded and another step to iterate through the tree.
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...

riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Re: Iterating through Tree and open subtrees dynamically

Post by riccardo » Mon Oct 03, 2011 4:27 pm

I tried to do so, but even here I do have the problem that obviusly the childerns do not exist. The first two items get opened without any problems but then it stucks...

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

Re: Iterating through Tree and open subtrees dynamically

Post by Ciege » Mon Oct 03, 2011 4:55 pm

What component (3rd party?) are you using for your tree view?

We use a DevExpress tree view in our AUT. In our tree view I can click on the top most parent tree item, type - to collapse all subordinates then type + to expand all subordinates.

Also, as I mentioned, you can look into using InvokeRemotely to invoke the ExpandAll of your tree.
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...

riccardo
Posts: 30
Joined: Wed Apr 28, 2010 10:37 pm

Re: Iterating through Tree and open subtrees dynamically

Post by riccardo » Mon Oct 03, 2011 5:07 pm

In this case we used Infragistics. By the way you are right, if I manually open all subitems, then the code works fine and goes through all the items.

I do not know how InovkeRemotely works. Is there any description about that?

Regards
Riccardo

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

Re: Iterating through Tree and open subtrees dynamically

Post by Ciege » Mon Oct 03, 2011 5:16 pm

First thing first... try using a simple method of expanding the tree first (like using keyboard shortcuts). No need to do anything fancy if you can do it using the keyboard.
If you cannot find a proper keyboard shortcut to do it, then search this forum about InvokeRemotely.
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...