Forum Discussion

hzheng2000's avatar
hzheng2000
Occasional Contributor
14 years ago

The menu item 'Open' is disabled

I am new to TestComplete. Currently I am using TestComplete 8 to generate script to test a Window application. One of the steps requires the user to click the file->open and load a file. But I am getting an error "The menu item 'Open' is disabled' when running the test. I tried to add a 'check point' to make sure the file menu is enabled. However, the 'check point' generating wizard doesn't allow me to do so. I couldn't move the red color frame over to the menu bar. What did I do wrong? 



Thanks


Hao  

1 Reply

  • Hi,



    Normally (in Win32 applications), menus are not individual objects, they are always assigned to a window. You can check whether a menu item is enabled by using the script below.



    function isMenuItemEnabled(menu, item)

    {

    var currentItem = item.match(/(\w*)\|/);

    if(!currentItem)

    {

    currentItem = item;

    item = "";

    }

    else

    {

    item = item.replace(currentItem[0], "");

    currentItem = currentItem[1];

    }



    for(var i = 0; i < menu.Count; i++)

    {

    var cur = menu.Items(i);

    if(cur.Caption != currentItem) continue;

    if(item != "")

    if(cur.SubMenu) return isMenuItemEnabled(cur.SubMenu, item);

    else return false;



    return cur.Enabled;

    }



    return false;

    }



    function sample()

    {

    var menu = Sys.Process("notepad").Window("Notepad").MainMenu;

    Log.Message(isMenuItemEnabled(menu, "Edit|Cut"));

    }