Forum Discussion

jonan's avatar
jonan
Occasional Contributor
7 years ago

How to check if a menuItem is visible?

I am currently testing a WPF application and getting all menus and submenus.

However, when I use the WPFmenu.Items property, it is giving me all submenus which are not visible on the actual GUI.

 

Is there a way to check whether a menuItem is visible? 

I have checked for Enabled property and it doesn't work as I expect it to.

 

# menuItem - TestComplete MenuItem Object

# menuObj - User-defined class rssMenu 

def getSubMenuRecursive(menuItem,menuObj):
     # If a menu, has a submenu get the number of submenus
     if (menuItem.SubMenu != None):
          subMenuCount = menuItem.SubMenu.Count
     # else return, there is nothing to recurse
     else:
          subMenuCount = 0
     # Recurse to find all the linked subMenus
     for i in range(subMenuCount):
          subMenuItem = menuItem.SubMenu.Items[i]
          if (subMenuItem.Enabled == True):
          subMenuItemObj = rssMenu(subMenuItem,menuObj)

          # I want a submenu to be added to menuObj.submenu[] only when it is visible on the application
          if (isVisible(subMenuItem) == True): 
               subMenuItemObj = getSubMenuRecursive(subMenuItem,subMenuItemObj)
               menuObj.addSubMenu(subMenuItemObj)


     return menuObj

 

---------------------------------

# User-defined rssMenu

class rssMenu():

     def __init__(self,obj = None,parent = None):
     self.name = obj.Caption
     self.parent = parent
     self.subMenu = []

     def addSubMenu(self,obj):
          self.subMenu.append(obj)
          return

 

3 Replies

  • Marsha_R's avatar
    Marsha_R
    Champion Level 3

    Try using the Object Spy tool on that item and open up the Advanced properties.  If you don't see a Visible tag in there, post a screenshot of all the properties and we'll try to help from that.

    • jonan's avatar
      jonan
      Occasional Contributor

      Hi Maria,

       

      Thanks for your reply.

      I have tried to spy the object and when I do, it does give me the Visible property.

      However, it also gives me a different way to access the object. Not through the WPFmenu.Items[] field but through a PopupRoot.

      I have also tried to FindAllChildren of this PopupRoot window but it cant return me the correct menuItems.

      • Marsha_R's avatar
        Marsha_R
        Champion Level 3

        Try doing a recording and clicking on a few of the menu items.  Open up the object names that are saved in the recorded test and see how each item is named.  You should be able to access them the same way.