Forum Discussion

jz's avatar
jz
New Contributor
13 years ago

How to generate Click event on a WPF menuItem

Under context menu i can get all the menuItems

but when i try to click



menuItem1["Click"](12,4);



it says the method is not supported



i can focus each menuItem but cannot generate the click on an menuItem as i iterate through the collection of contextMenu



var m1 = contextMenuBar["Items"];

     var flag = 0;

     var countMenuItem = 0;

     for (var i=0; i < m1.Count ; i++)

     {

        var t1 = m1.Item(i);

        var ctrlName = t1.ClrClassName;

        if ( ctrlName != "MenuItem" )

        {

            continue;

        }

        if ( ctrlName == "MenuItem" )

        {

           var h1 = t1.Text.OleValue;

           Log["Message"]("Current Menu Item is "+h1);            

           Log["Message"]("Current Menu Item Item Index "+countMenuItem)

           t1["Focus"];

           t1["Click"](12,12); // this does not work it give error on runtime







Any help regarding this will be appreciated. Already spent too much time on it.

I think it is the about WPF that i am not getting it



i will post it to the support also



DEv is saying i should do the raiseEvent

 but how can i create the raiseEvent type in testcomplete

t1["RaiseEvent"](e)



how can generate e which is System.Windows.RoutedEventArgs
  • irina_lukina's avatar
    irina_lukina
    Super Contributor

    Hi Jaffar,


    As far as I know, to simulate the click on the needed submenu item, you need to use the following code:



    MenuObg.Click(Index)



    Here, the Index parameter specifies a zero-based index of the submenu item within the items collection.


    Please, try an approach I suggested and provide me with the results. Thanks :)