This project is read-only.

Problem with tab control in WPF application

Jul 9, 2010 at 2:18 PM
Edited Jul 9, 2010 at 2:19 PM

I've run into a problem when trying to get items from a WPF window with a tab control. 

The tab control contains a number of other controls and I'm following the advice given in this thread

However, regardless of the currently selected tab I only ever seem to obtain items from the first tab page. UISpy shows the items as being children of the TabItem elements however it correctly shows items for the currently selected tab. Therefore I don't see how White could be retrieving any other item. 

The code is something like this:

// items added to the list on the selected tab
// at this point the new tab with the empty list is selected, no list items are visible as the new list is empty
White.Core.UIItems.ListView list = window.Get<White.Core.UIItems.ListView>("ItemsList");

// the following assert fails as there are items in the list, despite the list being visibly empty
Assert.AreEqual(0, list.Rows.Count, "0 rows expected in list");

This one is driving me a bit crazy so hopefully some has a solution! Thanks. 


Jul 9, 2010 at 3:31 PM
Edited Jul 9, 2010 at 3:33 PM



since .Net 4.0 we have the same problem (with .Net 3.5 not)


the elements are there because if you know the automationId's or names you can get the elements from the tab but UISpy and UIAVerify can see only the first tab.


what is the seen row count?



Jul 9, 2010 at 3:46 PM
Edited Jul 9, 2010 at 3:46 PM

Hi, The row count I'm getting is for the first list. So if I add 20 files to the list, create a new tab and switch to the new tab with an empty list, the row count is 20. 

How do you work around this? I've tried to get the selected tab page and then search for the items within that but even that produces the same result, although I've no idea why! 


Jul 9, 2010 at 3:59 PM

try getting the tab element and get the listview from the tab


Problem: it seems both listviews have the same AuID, and White found with Get only the first in the visual tree (visible or not is not a reason not to find it)


or try GetMultiple from window than you should get a List of IUIitems which can be cast to ListView, but the first way is the best I think.



Jul 9, 2010 at 4:16 PM
Edited Jul 9, 2010 at 4:16 PM
Thanks, yes I did try your first suggestion however it still returns a list with 20 items. I've no idea how that can be the case. My code below:

White.Core.UIItems.TabItems.ITabPage selectedTab = mainWindow.Tabs.First().SelectedTab;
System.Windows.Automation.AutomationElement listItem = selectedTab.GetElement(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("ItemsList"));
White.Core.UIItems.ListView list = new White.Core.UIItems.ListView(listItem, new White.Core.UIItems.Actions.NullActionListener());

I will keep digging.

Jul 9, 2010 at 4:21 PM
Edited Jul 9, 2010 at 4:21 PM

Ok I've tried GetMultiple:

White.Core.UIItems.IUIItem[] items = mainWindow.GetMultiple(White.Core.UIItems.Finders.SearchCriteria.ByAutomationId("ItemsList"));

It only returns one list; the first list containing the items, not the visible list with no items. 

Jul 9, 2010 at 4:40 PM
Edited Jul 9, 2010 at 4:41 PM

that is strange, I don't think that this is only a white issue, it seems to be a UIAutomation Problem

can you change the automation ID's of the listViews in each ta, or can the developer change them?



Jul 9, 2010 at 4:47 PM
Edited Jul 9, 2010 at 4:48 PM

I've just tried this with AutomationElement.FindAll passing the AutomationId as the criteria and it returns both lists.

 To me this seems like a bug in White. The only way I can think of working around this is to use UI Automation

to search by AuId and the IsOffscreen property to only return the visible item.

Jul 9, 2010 at 4:54 PM

oh than you are right


You know that you can change a AutomationELement to a named White Element?

In some cases I work this way to have easy access to the special options of controls.


Hope that the developer of White come back fast :(



Jul 18, 2010 at 9:29 AM

any chance of getting hold of some sample code to reproduce it?