Forum Discussion

sergi's avatar
sergi
Contributor
11 years ago
Solved

Use FindChild for MenuItems with "_" in WPControlText

Hi,

I want to use built-in FindChild function to find the items in the application menu.

I'm trying the following tod o it the following way:



Sys.Process("ApplicationNmae").FindChild(new Array("ClrClassName", "WPFControlText"), new Array("MenuItem", "File"))



The problem is that the WPControlText is actually "_File" instead of "File".



Has anyone any idea of how to overcome this? (I can't provide beforehand the position of "_" character).

  • Ok so I do something similar to this but I have a pretty length set of procedures to find items by text so I'll keep it as simple as I can.



    Sys.Process("ApplicationNmae").FindChild(new Array("ClrClassName", "WPFControlText"), new Array("MenuItem", "*"))



    Return all objects into an array and check the MenuItem property of each item individually stripping the _ and any other invalid characters from the value.



    Not sure what language you are using but I can provide an example if you'd like.

12 Replies

  • Ryan_Moran's avatar
    Ryan_Moran
    Valued Contributor
    I won't include all sub-functions but you can hopefully get an idea of what i'm doing here.

    propExists function validates the property i want to compare

    objPropVal returns the value of that property

    esc removes all invalid characters

    Where o is the object array returned by findall/findchild and s is the string value to find:




    function cprop(o,s){


    for (var c = 0; c < o.length; c++){


     var aTmp = new Array();


     if (propExists(o,'Caption')){aTmp.push(objPropVal(o,'Caption'));}


     for (var a = 0; a < aTmp.length;a++){



       return o;


       }


      }


     }


    return undefined;


    }


     




  • Thanks Ryan,

    That's very similar to what I'm doing.