Hi, I'm coding UI tests and the most common task is to navigate to controls situated in different tabs using automation. The problem is I can't get the content of tabs except the tab selected by default. That is, I change between different tab pages and only the first one's automation tree is visible. The code is something like that below. The default WPF tab control works fine: I can get the content of currently selected tab. So how can this problem be solved? Thanks in advance.
[TestMethod]public void TestMethod(){ // find app window var cond = new PropertyCondition(AutomationElement.NameProperty, "MainWindow"); AutomationElement foundWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, cond); // find tab control cond = new PropertyCondition(AutomationElement.ControlTypeProperty, System.Windows.Automation.ControlType.Tab); AutomationElement foundTab = foundWindow.FindFirst(TreeScope.Subtree, cond); var tabCtl = (WpfTabList)UITestControlFactory.FromNativeElement(foundTab, "UIA"); foreach (var tab in tabCtl.Tabs) { var elements = ""; Mouse.Click(tab); // do something to controls, // for example collect their names foreach (var el in Walk(tab.NativeElement as AutomationElement)) { elements += string.Format("Name: '{0}', Type: '{1}'\n", el.Current.Name, el.Current.ControlType.ProgrammaticName); } MessageBox.Show(elements); }}// Recursively walk an automation treeprivate List<AutomationElement> Walk(AutomationElement current){ var res = new List<AutomationElement>(); if (current != null) { res.Add(current); res.AddRange(Walk(TreeWalker.RawViewWalker.GetFirstChild(current))); res.AddRange(Walk(TreeWalker.RawViewWalker.GetNextSibling(current))); } return res;}