Forum Discussion

amithsid's avatar
amithsid
Contributor
11 years ago

How to work with Menu-bar items-Cannot be Spied

Hello,



I am not able to spy menu bar.



The tree structure of the path is also failing at times-

obj.Click("item1|item2|item3");



The text recognition is also failing at times.



Please help.



Thank you,

Amith n g
  • Hello Tanya,



    Thanks for helping me with the script.

    Can I remove the Log.LockEvents(); part od it and make it as a generic function which only performs the click on a menu item, leaving off the Log part of it?



    Thanks,

    Amith n g

  • Hi Tanya,



    Can you post VB script version for the same Clickitem function. I would like to try on my application where I am getting issues on clicking Menu items.



    Thanks,

    Jyothi
  • Hi Tanya,



    I tried the attached script (both VBscript and Jscript versions) and it failed at line number 33

    (itemCount = items.Count) . It looks like it's not recognising items, then I changed line number 14  to Set w =  Aliases.Ascend.frmMDI.MdiClient.frmDesktop.MainMenu1.Items (added . items). Then I was able to see the items.count as 8 in the watch list. But it failed at the line number 37 (currentItem = items.Items(itemId)).  It looks like it is not recognising items.items.



    The screen shot of my .Net application is also attached.





  • I am unable to attach the attachement 



    please find the code the here



    Hi Tanya,



    I tried the below script (both VBscript and Jscript versions) and it failed at line number 24

    (itemCount = items.Count) . It looks like it's not recognising items, then I changed line number 11  to Set w =  Aliases.Application.frmMDI.MdiClient.frmDesktop.MainMenu1.Items (added . items). Then I was able to see the items.count as 8 in the watch list. But it failed at the line number 37 (currentItem = items.Items(itemId)).  It looks like it is not recognising items.items.



    The screen shot of my .Net application is also attached.






    Sub Test1


      Dim ascend


      Dim mdiClient


      Dim frmQuery


      Dim toolStrip


      Dim w


      Dim result  


      Set app = Aliases.application


      Set mdiClient = app.frmMDI.MdiClient


        Call aqObject.CheckProperty(Aliases.application.frmMDI.MdiClient.frmDesktop.MainMenu1, "Enabled", cmpEqual, True)


        Set w =  Aliases.Application.frmMDI.MdiClient.frmDesktop.MainMenu1


      Set result = ClickItem (w, "Tools|Advanced Database connections|Sql Query", 0)


      Set frmQuery = mdiClient.frmQuery


      Call frmQuery.splitContainer.SplitterPanel.txtQuery.Keys("![ReleaseLast]delete customers")


      Set toolStrip = frmQuery.Toolbar1


      Call toolStrip.ClickItemXY("Execute (F8)", 36, 20)


      Call toolStrip.ClickItemXY("&Back", 21, 20)


    End Sub


     


    Function ClickItem (items, itemStr, level)


    tempResult = False


    Dim itemArray, currentItem, itemCount


    itemArray = Split(itemStr, "|", -1, 1)


    itemCount = items.Count


    For itemId = 0 to 9


       currentItem = items.Items(itemId)


      If SameText(currentItem.Caption, itemArray(level)) Then


           Log.LockEvents()


           items.Select("[" + itemId + "]")


           Log.UnlockEvents()


            Delay(500)


           items.Click("[" + itemId + "]")


           tempResult = true


      else  if (level < itemArray.length - 1) Then


          tempResult = ClickItem(currentItem.SubMenu, itemStr, level + 1)      


          return tempResult


         End If


       End If 


      return tempResult


    Next


    End function