Forum Discussion

chubaccak's avatar
15 years ago
Solved

How to check if item is not available in treeview

Hi, I am evaluating TestComplete 7 and  I am stuck on getting TestComplete to check if an item exist in treeview. For Example: I have a treeview with a parent node A and there is a child under ...
  • TanyaYatskovska's avatar
    TanyaYatskovska
    6 years ago

    Hi M-H-Mukit,

     

    You can find Yuri's reply from the mentioned topic below.

    However, I would like to draw your attention that this topic is very old. TestComplete has been improved significantly since that time. I suggest that you create your own topic here and describe what you would like to achieve. 

     

    Yuri's reply:

    Hi,

    You can use code like this:

    function treeItemExists(tree, itemPath)
    {
      var items = itemPath.split("|");
      var treeItems = tree.wItems;
      var found = false;
      for(var item in items)
      {
        found = false;
        if(!treeItems) break;
        
        for(var i = 0; i < treeItems.Count; i++)
        {
          if(treeItems.Item(i).Text == items[item])
          {
            found = true;
            treeItems = treeItems.Item(i).Items;
            break;
          }
        }
      }
      
      return found;
    }
    ...
      var tree = // Obtain the tree view
      if(!treeItemExists(tree, "Shipowners|A1|Chemical"))
        Log.Message("Item does not exist in treeview")
      else
        Log.Message("Item exist therefore delete of item was not successful") 
    ...