Unable to access the content of a TabItem Control

Apr 13, 2010 at 11:40 PM

I have a TabControl with multiple TabItems. These TabItems have multiple controls in them but I see no way to obtain a reference to them.

I am able to get references to the White TabPage objects that represent the TabItems for the TabControl, however the TabPage object doesn't give me access to it's child controls.  This means that all of the buttons,textboxes etc inside of the TabItem can't be accessed. 

UISpy and VisualUIAVerify can't find any of these nested controls either.

window.GetMultiple(SearchCriteria.All); is also unable to get a reference to these controls.

Based on the documentation at http://msdn.microsoft.com/en-us/library/ms751611.aspx I should be able to navigate child controls it seems like.

I tried the following code to try 

ITabPage selected = tabs.SelectedTab;    //this returns valid reference       
AutomationElement elementNode = TreeWalker.ControlViewWalker.GetFirstChild(selected.AutomationElement); //elementNode is null
elementNode = TreeWalker.ContentViewWalker.GetFirstChild(selected.AutomationElement);//elementNode is null

The treewalkers in both cases however return null.  Is this issue because a TabItem doesn't follow the same pattern as other containers in that it has a Content property of type object.  So the type might be Text,Image or a Pane.  So in order to obtain references to the child elements you would need to check the type of the Content property and handle that on a case by case basis?  Is there a way to actually get a reference to the actual TabItem.Content property? I see no other way to get the child items in a TabItem.


Apr 14, 2010 at 6:37 AM
Hachima wrote:

UISpy and VisualUIAVerify can't find any of these nested controls either.


Than this is the problem :(


if these tools don't see the elements you can't access them with UIAutomation and so also not with White.

UIAutomation works something like client/server,

your test is the client, the application the server.

If controls don't implement the server parts (AutomationPeer for example) you can't access them.


Click events will work if you move the mouse to the correct position and click, but that's all.