Forum Discussion

sergeys's avatar
sergeys
Contributor
10 years ago

Window was destroyed - choosing menu items

I'm facing the following problem : when I'm trying to select menu it doen't work sometimes and fails with 'Window was destroyed....' error.

 

I'm trying to click menu View > Go to Page > Pricing > Events - plz. see 'MenuItem.png'

 

I set Mouse Movement to 0 and use the following method - Aliases.MyApp.WaitAliasChild("MainForm", -1).MainMenu.Click("View|Go to Page|Pricing|Events");

 

So, I tried to solve it by adding delay aqUtils.Delay(1000) before - and it worked sometimes, but it started to fail again.

Then I started using refresh Sys.Process("MyApp").Refresh() before delay - and it worked stable for some time, but it started to fail again :(

 

Then I tried to Click on menu using Aliases.MyApp.WaitAliasChild("MainForm", -1).MainMenu.Items("View").SubMenu.Items("Go to Page").SubMenu.Items("Pricing").SubMenu.Click("Events");

but it causes runtime error with The control item 'Pricing' not found. message

 

I investigated items using Object Spy and it turned that Aliases.MyApp.MainForm.MainMenu.Items("View").SubMenu.Items("Go to Page").SubMenu.Count is -1

Please compare SubMenu for 'Go' and 'Go to Page' sub items attached

 

Tryed to use Aliases.MyApp.MainForm.Menu.MenuItems.Item(2).MenuItems.Item(3).MenuItems.Item(4).MenuItems.Item(0).PerformClick();, but it didn't work - no exception , but menu is not selected -  PerformClick.png attached

 

So, for now the most 'stable' case is the first one - using Click the whole menu path....

 

Can smbody help me with it please?..

4 Replies

  • djadhav's avatar
    djadhav
    Regular Contributor

    Please attach some screenshots explaining the above.

    • sergeys's avatar
      sergeys
      Contributor

      Hi there,

       

       

      I edited my initial message and added some screenshots.

       

      I added Event for errors:

      function GeneralEvents_OnLogError(Sender, LogParams)
      {
      if ((LogParams["Str"] == "The window was destroyed during method execution.") || 
      (LogParams["Str"] == "Cannot find the submenu for the '?' menu item.")) {
      LogParams["Locked"] = true;
      Aliases.MyApp.WaitAliasChild("MainForm", -1).MainMenu.Click(Project.Variables.selectMenu);
      }
      }

       

      So, now when errors appear it tries to select menu one more time - until it is selected.

      BUT, now I see that there can be no errors and menu is not selected, still.

      So, I added

      do while (menu is selected)

      function, not too great solution, but I believe it will work OK....

       

      That would be great to know anyway, is there any GOOD solution, and not one I implemented recently.

      • AlexKaras's avatar
        AlexKaras
        Icon for Champion Level 1 rankChampion Level 1

        Hi,

         

        You might consider to consult with developers to check the following idea:

        -- It is possible that sub-menu and its items are created dynamically and only after the corresponding parent menu item is clicked or hovered to expand;

        -- If the above is the case, you may consider not to click menu by its full path using default TestComplete's functionality, but implement it manually;

        -- In your manual implementation, for every but final menu item, test code must: a) hover mouse over the menu item; b) click the hovered menu item or just wait until the sub-menu appears (this may depend on the implementation); c) search for the next menu item in the sub-menu window. The last menu item should be just clicked.

         

        Hope, this might help.