How can I click button with name starting with &

Oct 23, 2012 at 12:17 PM

In my application there is one messagebox with OK button  name = "&OK"

i am not able to click it with name but i am able to click it by ControlType. following is the properties :

ClassName: ""
    ControlType: "ControlType.Button"
    Culture: "(null)"
    AutomationId: "11864360"
    LocalizedControlType: "button"
    Name: "&OK"
    ProcessId: "4968 (VeManagement.Client)"

Oct 23, 2012 at 1:13 PM

Hi can you please show your code snippet?

Oct 24, 2012 at 6:26 AM

I have created a Common Function for Button Click elsewhere it works but it fails when the button name comes with name "&OK":

   Window InvaildInputWindow = app.GetWindow(SearchCriteria.ByControlType(ControlType .Window), InitializeOption.NoCache);
                if (InvaildInputWindow.Name.Equals("Invalid Details"))
                    ButtonClick (InvaildInputWindow, "&OK");

public void ButtonClick(Window win, string buttonName)
            Button ButtonObj = win.Get<Button>(buttonName);
            if (ButtonObj != null )
                Console.WriteLine(buttonName + "Button Clicked");
                Console.WriteLine("Button not found");