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 A called Test and under Test there is a child item call Item1 & Item2. If I delete Item2 how can I verify that Item2 is no longer in treeview?



I have the following written in Jscript but it does not work.



if ( ! treeview.wItems.Item("A|Test|Item2").Exists)

  Log.Message("Item2 does not exist in treeview")

else

  Log.Message("Item2 does exist in treeview")



Please Help!



Thanks

Kathy
  • 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") 
    ...

3 Replies

      • TanyaYatskovska's avatar
        TanyaYatskovska
        SmartBear Alumni (Retired)

        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") 
        ...