locked
How to click on the button that is there in a content dialog for a UWP app? RRS feed

  • Question

  • Hi 

    I am testing an UWP app with coded UI. I have a content dialog box with two buttons Yes & NO. 

    Coded UI fails to find the control for Yes & No buttons. 

    In the test builder when I highlight the parent for the content dialog box is shown as the Main Window, not the content window. 

    That is the way to develop UWP apps. 

    To reproduce the similar problem, please follow the steps: 

    1) Open movies app

    2) Click on the add button

    3) Try to click on the add button 

    Coded UI throws an exception "Playback failed to identify the control"

    Please help on how to resolve the issue, where in the parent is still been shown as main window. 



    Thursday, January 18, 2018 1:48 PM

All replies

  • Hi thakurAnunay,

    Thank you posting in MSDN forum.

    According to your description, your problem is caused by content dialog box. The button on the content dialog box cannot be accurately identified during playback. So, please first find the content dialog box and highlight it, then, find the button in that content dialog box and click on it.

    Following example code work fine in content dialog box UWP App, please reference:

    XamlControl contentdialog = new XamlControl();
                contentdialog.SearchProperties.Add(XamlControl.PropertyNames.Name, "AppContentDialog");
                contentdialog.SearchProperties.Add(XamlControl.PropertyNames.ControlType, "Window");
                contentdialog.DrawHighlight();
                XamlButton button = new XamlButton(contentdialog);
                button.SearchProperties.Add(XamlButton.PropertyNames.ControlType,"Button");
                button.SearchProperties.Add(XamlButton.PropertyNames.Name, "Button1");
                Mouse.Click(button);
    

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    • Edited by Judy ZhuY Friday, January 19, 2018 9:18 AM
    Friday, January 19, 2018 9:17 AM
  • Hi Judyzh 

    Thanks for the response, the above code works for the default content dialog box, but my app I have custom content dialog box, 

    If you have a button in the content display text area, the control goes to the main window rather than the content dialog window. 

    For eg. in the below snapshot the parent for the hello button is shown as the parent window not the content dialog box, so coded UI fails to tap on the hello button

    And for button1 and button2 the parent is been shown as a content dialog, so coded UI works fine with that. 

      In UWP app by default the content dialog is allowed to have only two buttons, if the app requires more that two button the we have go to for custom content dialog box. 


    Monday, January 22, 2018 6:10 AM
  • Hi thakurAnunay,

    I test with the test button in the content dialog box, please refer to following example code.

     XamlControl contentdialog = new XamlControl();
                contentdialog.SearchProperties.Add(XamlControl.PropertyNames.Name, "AppContentDialog");
                contentdialog.SearchProperties.Add(XamlControl.PropertyNames.ControlType, "Window");
                contentdialog.DrawHighlight();        
                XamlControl viewerpane = new XamlControl(contentdialog);
                viewerpane.SearchProperties.Add(XamlControl.PropertyNames.ControlType,"Pane");
                viewerpane.SearchProperties.Add(XamlControl.PropertyNames.ClassName, "ScrollViewer");
                viewerpane.SearchProperties.Add(XamlControl.PropertyNames.AutomationId, "ContentScrollViewer");
                viewerpane.DrawHighlight();
                XamlButton button = new XamlButton(viewerpane);
                button.SearchProperties.Add(XamlButton.PropertyNames.ControlType, "Button");
                button.SearchProperties.Add(XamlButton.PropertyNames.Name, "test");           
                Mouse.Click(button);

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Judy ZhuY Tuesday, January 23, 2018 7:22 AM
    • Unproposed as answer by Judy ZhuY Tuesday, February 6, 2018 2:21 AM
    • Proposed as answer by Judy ZhuY Tuesday, February 6, 2018 2:21 AM
    Monday, January 22, 2018 9:18 AM
  • Hi thakurAnunay,

    How is it going with the issue currently?

    If my reply helps you resolved your issue, would you please mark it as answer, if not, please feel free to let me know.

    Thank you very much.

    Regards,

    Judyzh


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 1, 2018 8:38 AM