Illustration of Coded UI Test playback failure – "Search may have failed at ControlX as it may have virtualized children …"

In one of my earlier blogs here, I had explained the some search failure scenario and how to go about tackling the problem. As a continuation to that, I’m providing a simple application scenario and the solution here.


My test scenario is to click on a tree item “Sub Item #1” for a simple WPF app as shown in the snapshot below:

 WPF App Snapshot


Open a Coded UI Test project, and record a click on the “Sub Item #1” Tree Item. Your recorded method will show up something like –


        public void RecordedMethod1()


            #region Variable Declarations

            WpfTreeItem uISubItem1TreeItem = this.UIMainWindowWindow.UIItemCustom.UIItemTree.UIRootTreeItem.UIItem5TreeItem.UISubItem1TreeItem;



            // Click ‘Root’ -> ‘Item #5’ -> ‘Sub Item #1’ tree item

            Mouse.Click(uISubItem1TreeItem, new Point(38, 8));



When you run the test, it will fail due to a search failure.


Test method SearchHierarchyFix.CodedUITest1.CodedUITestMethod1 threw exception:

Microsoft.VisualStudio.TestTools.UITest.Extension.UITestControlNotFoundException: The playback failed to find the control with the given search properties. Additional Details:

TechnologyName:  ‘UIA’

ControlType:  ‘TreeItem’

Name:  ‘Sub Item #1’

 Search may have failed at ” TabList as it may have virtualized children. If the control being searched is descendant of ” TabList then including it as the parent container may solve the problem. —> System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.


Going by the description I provided in the previous blog, the issue over here is that the search failed even before it reached the target element i.e. uISubItem2TreeItem. It failed at an intermediate element itself, in this case ‘UIItemCustom’. The reason being, the ancestor TabList and TabPage controls are not being auto-generated as part of the search hierarchy. The ideal search hierarchy should have been


instead of



So how do we fill the missing ‘UIItemTabList.UITab1TabPage’?


1.       Launch the Coded UI Test builder once again.

2.       Locate the “Tab #1” control by moving the cross hair over it.

3.       Add it to the UI object hierarchy. Close the Coded UI Test builder.

4.  In your test method, insert the following line of code before Mouse.Click(uISubItem1TreeItem, …)


            this.UIMainWindowWindow.UIItemCustom.Container = this.UIMainWindowWindow.UIItemTabList.UITab1TabPage;


This essentially does what I described in the blog. It stitches the search tree to include the UIItemTabList & UITab1TabPage as the ancestor of UIItemCustom.

(Unlike what I mentioned in the blog, you do not actually have to do an additional UITab1TabPage.Container = this.UIMainWindowWindow.UIItemTabList since the uITab1TabPage already has a good search hierarchy of its own.)

The missing link was making the search from UIMainWindowWindow to UIItemCustom work successfully, which we achieved by inserting this UIItemTabList.UITab1TabPage in between them by using the .Container property.


I’ve attached the test application and the Coded UI Test solution for reference.

Comments (8)

  1. i have s similiar case:

    the coded ui did genatre to me

    wpfControl  button = this.mainWindow -> AppGrid -> button.

    (i havent builid this app).

    but i think it miss some controls on the way, and when i am opened the codedUiBuilder (to add the missing controls) – i couldnt locate them.

    any ideas?



  2. Abi says:


    Thanks a lot for ur post!! This ended my three weeks of search. I just followed the same approach for my dev express based win forms. It worked like a charm.

  3. Hans-Peter says:


    we have already VS2013 and it is still the same. To record the additional controls manually is some work but it could be done. But what about setting the Container? Is there a simple way to add this statement to hundreds of recorded actions?

  4. Sherin says:

    Thank you so much. It really helped me finally get access to a grid control I was having access issues

  5. Nazeer M says:

    Hey how to modify this concept if I have a "TabPage" where its AutomationID changes everytime. In my case it worked for the first search but later it didnt work for other accounts as the TabPage has varried AutomationID.

    WpfCustom stich = this.XXXWindow.UIItemCustom1.UIAccountProfileCustom;

    this.XXXWindow.UIItemCustom1.Container = this. XXXWindow.UIItemCustom2.UINxgMain_Middle_CardTabList.UIItemXXX999111YYYYTabPage.UINxgMainAccountCardCustom;

    Mouse.Click(stich, new Point(183, 30));

    The above code worked for me but the Tab Page(UIItemXXX999111YYYYTabPage) changes its AutomationID everytime and hence It fails. Please assist a solution for this problem.

  6. Nazeer M says:

    Hey I was able to automate using this concept. Thank you Tapas!!!!!

  7. EugeneMac says:

    this.UIMainWindowWindow.UIItemCustom.Container = this.UIMainWindowWindow.UIItemTabList.UITab1TabPage;

    It's cool but this string will disappear after next Build.

  8. Jean M says:

    Thank you for this!!! You saved me hours of head scratching