Hey Vlad,
I've faced a similar problem with one of my applications, due mostly to the need to support legacy Janus controls. What I ended up doing was mapping the menu items as children of the menu bar, then calling a helper function to discover them in the future. I don't know if it will help you, but here are my steps:
1. Identify the top-most menu
2. Use MenuCrawler() to print the children to the Log
3. Use the log to create a reverse-lookup
4. Use the reverse lookup to create a click method
This method is chalk full of potential pitfalls, but for my particular situation this method was a good jumping off point. Good luck out there.
- Howie
function MenuCrawler()
{
//put in the name of the top-most menu
GetSubMenu(Aliases.<Product>.Form.UICtrlsMainMenu, "[");
}
//this method recursively searches for child menu items
function GetSubMenu(menu, prefix)
{
if(menu == null) { return; }
var count = menu.Count;
if(count == null || count <= 0){ return; }
for(var i = 0; i < count; i++)
{
Log.Message(prefix + i + "] :: " + menu.Items(i).Caption); //this might need to be ".Text" or ".Content" depending on the circumstances
GetSubMenu(menu.Items(i).SubMenu, prefix + i + "|");
}
}
/* Some sample log output:
[0] :: File
[0|0] :: New
[0|1] :: Save
[0|2] :: Quit
[1] :: Help
[1|0] :: Contact
[1|1] :: About
*/
//new lookup method:
//this method returns the whole control, in case you need ".Enabled" or ".Visible" and whatnot
function FindMenuItem(path)
{
var menu = Aliases.<Product>.Form.UICtrlsMainMenu;
switch (path)
{
case "File" : return menu.Items(0);
case "File|New" : return menu.Items(0).SubMenu.Items(0);
case "File|Save" : return menu.Items(0).SubMenu.Items(1);
case "File|Quit" : return menu.Items(0).SubMenu.Items(2);
case "Help" : return menu.Items(1);
case "Help|Contact" : return menu.Items(1).SubMenu.Items(0);
case "Help|About" : return menu.Items(1).SubMenu.Items(1);
default: return null;
}
}
//this method specifically clicks on the button in question
function ClickMenuItem(path)
{
FindMenuItem(path).Click();
}