Forum Discussion

gus's avatar
gus
Contributor
11 years ago

Getting ribbon item via Items.Item() fails

Hi,



Based on the article at , I'm trying to get a reference to a specific ribbon item using the following JScript code:



Sys.Process("FooApp").WinFormsObject("MainWindow").WinFormsObject("ribbonControl1").Items.Item("Manage Projects").Caption



I'd expect this to return "Manage Projects", but instead I receive a type mismatch error.



The following code returns the Manage Projects caption correctly:



Sys.Process("FooApp").WinFormsObject("MainWindow").WinFormsObject("ribbonControl1").Items.Item(1).Caption



It looks like TestComplete or JScript would not accept the caption as the parameter of the Item method, unlike the documntation confirms this is a legal way to access items.



Can you tell me the mistake in the first code line? I get the same results if I use the aliases defined.



Thanks in advance

Gusztáv

7 Replies

  • You need to make sure right parameters are passed in for function Item(...).



    We can check it by ourselves in Object Spy or in Object Browser:

    1. First get the ribbon control by Object Spy or in Object Browser

    2. Then Check properties for ITEM by clicking button on right side

    3. Check for Item(..), caption, and other properties we want to



    I've attached a capture of how it looks like in Object Spy.



    -Ocean
  • That's normal, which means only int is accepted for Item(...), you can see from the description of your capture. And that's why you get mismatch type from your code.



    There are some samples in the URL you pasted, you can try to get item from wItems:



    Sys.Process("MyRibbonApp").WinFormsObject("frmMain").WinFormsObject("ribbonControl").wItems.Item("QuickAccessToolbar").Items.Item("Paint style");



    -Ocean
  • gus's avatar
    gus
    Contributor
    Sorry, I just forgot a few environmental details:


    • I'm using TestComplete 9.31


    • The tested app is a .NET app


    • The ribbon control is a DevExpress XtraBar RibbonControl


    I have no specific information on .NET version (guessing it's 4.5) and DevEx version, please let me know if I should obtain these information.
  • gus's avatar
    gus
    Contributor
    Hi Ocean,



    Thanks for your reply. I did not know about what you showed in step 2 of the screenshots, namely that I can enter the index of the item I want to look up in Object Spy.



    What is interesting, however, is that I miss the type selector group on the Params dialog, and I can only enter a numeric index for a control of type DevExpress.XtraBars.Ribbon.RibbonBarItems. Is that normal? Based on the cited webpage in my opening post, I'd expect TC or DevEx, the responsibility of whichever this is, to accept string parameters for the index as well. Since the app contains cc 300 ribbon controls, enumerating them each time I need one would be time-consuming.
  • gus's avatar
    gus
    Contributor
    Hi again,



    You touched an important issue! Though the documentation mentions wItems often, I could not yet find any control or object supporting this property. Do I need to make any kinds of preparation to make it exposed in Object Spy or Object Browser?



    Gus
  • I can see property wItems for RibbonBar, usually it's under Advanced view -> Extended -> wItems.



    -Ocean
  • gus's avatar
    gus
    Contributor
    That's weird! I have attached a screenshot showing Object Spy for Microsoft Excel 2013 ribbon and the ribbon of the custom application, and none of them contain wItems. Should they?