Forum Discussion

alanbueno8's avatar
alanbueno8
New Contributor
8 years ago

How to check if a specific Item on a MenuItem object exist

I'm handling a MenuItem object, but this menu work with permissions filters and sometimes the option i need to interact isn't present on screen. 

 

To check if that option exist before send the action to the object, i access the Item in the position expected to be my option by the index and get the Caption property value. If that Caption matches with the option i expect, i send the action (click, selection, ...).

 

I'm looking in the SmartBear Community and Support for other ways, but not succesfully. Anyone can help?

 

C#:

 

//Items(4): Position i expect my option, if the user has permission to see it.

 

var expectedOptionName = "optionX";

var optionText = Menu["PopupMenu"].Items(4).Caption;

if(optionText == expectedOptionName)
{
    Menu["PopupMenu"]["Click"](4);
}
else
{
    Log["Message"]("Option is disabled for this user.");
}

2 Replies

  • djadhav's avatar
    djadhav
    Regular Contributor

    An easier option would be to use the FindChild method to find if the option exists.

     

    FindChild : https://support.smartbear.com/viewarticle/69449/

     

    Algorithm:

    ChildObject = ParentMenu.FindChild("Caption","OptionX",5)

    If ChildObject Exists

        Click It

    Else

        Display message

    • alanbueno8's avatar
      alanbueno8
      New Contributor

      Tks,