locked
Coded UI cannot find the control RRS feed

  • Question

  • Hi there,

    I trapped into an issue on coded ui framework when I am trying to find a control from window Ui tree(IDE is VS2013), when I try to find a control, it could be found only one time, but failed to find at second time...(the AUT doesn't changed at all) I tried several ways to resovle this issue, but not working well (e.g set AlwaysSearch = true, Renew a ui-object to find...)

    But it only can be found at second time when I force to cleanup coded UI playback setting...but I am not sure why I have to do this cleanup...we also met some case that the control still cannot be found...

    

     the control's hireachy of window tree and the control as below,

    Desktop

     -CurrentWindow

      -CurrentClient

       -AddressBar

       -OmniAddressBar (trying to find OmniAddressBar)

            public WinWindow CurrentWindow
            {
                get
                {
                    if (this.mCurrentWindow == null)
                    {
                        this.mCurrentWindow = new WinWindow();
                        this.mCurrentWindow.SearchProperties[WinWindow.PropertyNames.ClassName] = LocalData["MaterClient"]["Window_Name"];
                    }
                    return mCurrentWindow;
                }
                set
                {
                    this.mCurrentWindow = value;
                }
            }
            private WinWindow mCurrentWindow;

            public WinClient CurrentClient
            {
                get
                {
                    if (this.mCurrentClient == null)
                    {
                        this.mCurrentClient = new WinClient(this.CurrentWindow);
                        this.mCurrentClient.SearchProperties[WinClient.PropertyNames.Name] = LocalData["MaterClient"]["Client_Name"];
                    }
                    return this.mCurrentClient;
                }
            }
            private WinClient mCurrentClient;

            public WinClient AddressBar
            {
                get
                {
                    if (this.mAddressBarView == null)
                    {
                        this.mAddressBarView = new WinClient(base.CurrentClient);
                        this.mAddressBarView.SearchProperties[WinClient.PropertyNames.Name] = base.LocalData["AddressBarView"]["AddressBarView_Name"];
                    }
                    return this.mAddressBarView;
                }
            }
            private WinClient mAddressBarView;

            public WinEdit OmniAddressBar
            {
                get
                {
                    if (this.mOmniAddressBar == null)
                    {
                        this.mOmniAddressBar = new WinEdit(this.AddressBar);
                        this.mOmniAddressBar.SearchProperties[WinEdit.PropertyNames.Name] = base.LocalData["AddressBarView"]["OmniAddressBar_Name"];
                    }
                    return this.mOmniAddressBar;
                }
            }
            private WinEdit mOmniAddressBar;

    I'll be so appreciate if anyone can help me to resolve this problem



    • Edited by Jerry_Kuang Monday, November 7, 2016 10:58 AM
    Monday, November 7, 2016 9:47 AM

All replies

  • Hi Jerry_Kuang,

    According to your code, you find the control with this order mCurrentWindow-> mCurrentClient-> mCurrentClient-> mOmniAddressBar, so based on this code, we must make sure every control could be identified without any problems. I suggest you need to use DrawHighlight function to make sure these parent controls must be recognized successfully.

    But according to your codes, I suggest you could use another method to found the mOmniAddressBar control. Please refer to the following scenario:

    1). According to your description, you maybe want to recognize the mOmniAddressBar from a browser. We could use the cross button in Coded UI Test Builder (step 1 in the following screenshot), and generate it to UIMap.Designer.cs (step 2 in the following screenshot). Maybe like the following screenshot:

    2). Open the UIMap.Designer.cs, and found the control search properties value, then hand code to recognized it. Here is a sample to find the search control from IE. However the control’s direct parent control is not browser, and I set browser as its browse, and the Test Builder could recognized it successfully.

    BrowserWindow browser = new BrowserWindow();
    browser.NavigateToUrl(new Uri("http://www.bing.com"));
    WinMenuItem UISearchCtrlEMenuItem = new WinMenuItem(browser);
    UISearchCtrlEMenuItem.SearchProperties[WinMenuItem.PropertyNames.Name] = "Search (Ctrl+E)";
    UISearchCtrlEMenuItem.DrawHighlight();
    

    So you could refer to this code, at sometimes, we need not to find a control via level by level. And please feel free to let me know you latest results.

    Sincerely,

    Oscar


    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.

    Tuesday, November 8, 2016 5:40 AM
  • Oscar, Really thanks for your reply, today I also took some investigation on this issue and found something new here...

    1) There shouldn't be a control definition issue, the controls could be found on my peer's box, but not on my box..(I also double confirmed that we are using same VS, Coded UI Assemblies and dot-net version)

    2) I wrote the following test code and it passed on first seaching and failed at second times

    And I also ran this code on my peer box, no issues occurred and nothing debugging lines...

    Could you please help to figure out what's happened when searching controls...

    Tuesday, November 8, 2016 12:22 PM
  • Hi Jerry_Kuang,

    According to your description, your code could be run without any problems in your colleague’s computer. So I think this issue may be not related with the code, and it may be related to the VS. Please refer to the following steps to troubleshoot this issue:

    1). Please create a new coded UI project, and run it to observe whether has the same issue.

    2). Have you installed third plugins in your VS? If yes, please launch VS in safe mode (devenv /SafeMode) to try again.

    3). Please copy the code that run well in your colleague‘s computer, and run it in your own machine to observe whether has the same issue.

    4). Make sure the IE browse’s version is the same as your colleague’s and make sure browser is maximized and resolution is 100% during playback.

    Sincerely,

    Oscar


    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.

    Wednesday, November 9, 2016 1:36 AM
  • Hi Oscarw,

    Sorry for reply this late, I followed your above steps, but not works for me, but I have found something new here, when I created a new Coded UI project -> use record and replay-> the control could be found at second time, so I compared the difference between my code and coded ui generated code, finally I find the difference. Cause of my test application is a browser, the root window name always changed, so I add a dynamic getting window name method, everything works well

    if I didn't add dynamic window title, I have to find each control where is in control's hierarchy as below

    But I am still confusing why the same code can work on my peer' box, but not mine, why it work after I added root window name, any UI caches when I use coded UI to find controls, is there more graceful way to resolve issue

    • Proposed as answer by Oscar_Wu Thursday, November 17, 2016 8:29 AM
    • Unproposed as answer by Oscar_Wu Thursday, November 17, 2016 9:04 AM
    Monday, November 14, 2016 3:51 AM
  • Hi Jerry_Kuang,

    According to your description and the codes, you have used the chrome browser, whether this issue happened in IE browser?

    Just as you said, this issue is caused by browser, I think this may be caused by the compatibility between coded UI scripts and chrome, please make sure the chrome version is the same as your peers’.

    If possible, would you please share me a sample that could repro your issue, I will test it in my side to judge whether it is a bug in Coded UI, you could upload it to OneDrive and share a link here, thank you very much.

    In a world, glad to know that you have resolved this issue, and thanks for sharing your solution here. Would you please mark your reply as the answer? So it would be helpful for other members who meet the same issue as yours.

    Sincerely,

    Oscar


    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.

    Monday, November 14, 2016 5:28 AM