Forum Discussion

abdul_rp's avatar
abdul_rp
Contributor
14 years ago

Popmenu Items are not identified

Hi,




Items in StripPopupMenu are identified if the menu is as captured in Ref one and Items are not identified if the StripPopupMenu displays as Ref two and TC throws an Error as Captured in Popmenu Script Error in Runtime



Kindly provide me the solution for this problem



Regards,

Abdul


 

3 Replies

  • How about ContentMenu in WPF application? It also is not bound to the specific control.

  • Hello,





    I've modified the ClickMenuItem function to illustrate how to click items of a WPF unbound ContextMenu using their names.







    function ClickMenuItem(menu, path, parentWindow, proc)

    {

      var i, items, item, found, x, y, point;

      

      items = path.split("|");

      

      // Find the menu item to click

      found = false;

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

      {

        item = menu.Items.Item(i);

        if (item.Header.OleValue == items[0]) 

       {

          found = true;

          break;

        }

      }





      if (!found)

     {

        Log.Error("The '" + items[0] + "' menu item was not found");

        return false;

      }

      

      // Calculate the menu item's screen coordinates and click the found point

      var appDom = proc.AppDomain(proc.ProcessName + ".exe"); 

      var pnt = appDom.dotNET.System_Windows.Rect.Empty.Location;

       

      pnt.X = item.ActualWidth/2;    

      pnt.Y =  item.ActualHeight/2;    

      var locationFromWindow = item.TranslatePoint(pnt, parentWindow);

      var locationFromScreen = item.PointToScreen(pnt);

       x = locationFromScreen.X;

       y = locationFromScreen.Y;

      Sys.Desktop.MouseDown(VK_LBUTTON, x, y);

      Sys.Desktop.MouseUp(VK_LBUTTON, x, y);

      Delay(250);

      

      // Proceed to the next item in the path

      if (items.length > 1)

        if (!ClickMenuItem(item.DropDown, items.slice(1).join("|")))

          return false;

      return true;

    }







    Usage:







      var proc;

      var tabControl;

      var contextMenu;

      var mainWnd;

     // The process of the tested application

      proc = Sys.Process("WpfApplication1");





     // The window that owns the context menu 

     mainWnd = proc.WPFObject("HwndSource: MainWindow", "MainWindow").WPFObject("MainWindow", "MainWindow", 1);        

      ...

      ClickMenuItem(contextMenu, "Paste", mainWnd, proc);