May 31, 2012 at 4:47 PM

There is a strange inconsistency/deficiency with respect to Tabs and TabPages in White: Pages property of Tab is of type TabPages, which really is UIItemList<ITabPage>. Notice that it is a list of interfaces, instead of actual UIElements. The ITabPage interface does not even define the Get<>() method, so at this point I am at a loss as to how to get to the contents of a Tab (in a WPF application).

How do I get UIElements contained inside a TabPage?

Why is Pages an interface list? The interfaces don't make the full power of UIElement accessible...


Jun 6, 2012 at 11:08 PM
Typically I use an extension method to get a TabItem ("TabPage") from a Tab by name:

        public static TabPage GetTabPage(this Tab tab, string name)         {             TabPage tabPage = (TabPage)tab.Pages.Find(page => page.NameMatches(name));             return tabPage;         }

Casting to TabPage, you get a usual UIItem subclass, can use Get(), etc.

Also, you can use the method similar to the following to get a List<TabPage> (assuming that you already have the mainTab and it's window):

        public List<TabPage> GetTabPages()
            List<TabPage> tabPages = new List<TabPage>();
            AutomationElement ae = mainTab.AutomationElement;
            AutomationElementCollection tabItemAEs = ae.FindAll(TreeScope.Descendants, new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.TabItem));
            foreach (AutomationElement tabItemAE in tabItemAEs)
                TabPage tabPage = new TabPage(tabItemAE, window.ActionListener);
                if (!tabPage.IsOffScreen)
            return tabPages;
Jun 8, 2012 at 10:13 PM
Edited Jun 8, 2012 at 10:15 PM

Yes, I need to enumerate them because I don't know in advance what tab pages there are, as they are created dynamically. Your GetTabPages() is very handy. Thank you.