Ranorex

English|Deutsch

Dumping out the element tree

print friendly pageSometimes it can be useful to dump out the whole element tree to see the relationship of the items:
C#
static public void DumpElementTree(Element element, int level)
{
      level++;
      int childCount = element.GetChildCount;
      for(int index=0;index<childCount;index++)
      {
            Element child = element.GetChild(index);
            if( child == null )
            {
 
                  Console.WriteLine("  Cannot read child({0}",index);
 
                  continue;
 
            }
 
            // Select the child
            child.Select(Selection.TakeFocus | Selection.TakeSelection);
           
            Point point =  child.Location;
            Size  size  = child.Size;
            if ( !size.IsEmpty )
            {
                  Mouse.Move(point.X + size.Width/4, point.Y +
                  size.Height/2,50);
            }
                 
            String spaces = new String(' ',2*level);
           
            if ( !size.IsEmpty )
               Console.WriteLine("{0}Role={1} Name={2} Location=({3},{4})",
                   spaces,child.Role.ToString(),child.Name,point.X,point.Y);
            else
               Console.WriteLine("{0}Role={1} Name={2}",
                  spaces,child.Role.ToString(),child.Name);
                       
            DumpElementTree(child,level);
      }
}