Coded ui tests 无法在WinTable中迭代

Coded ui tests 无法在WinTable中迭代,coded-ui-tests,Coded Ui Tests,我有一个WinTable,我想用我的测试值检查一些行的值。由于每天都会添加新行,所以行索引值是动态的,我需要找到它。我需要迭代所有行,以获得我要检查值的正确行。但是,我还不能迭代表中的所有行 #region Variable Declarations WinTable uIG1Table = this.UIProMANAGEWindow.UIMouldOperationWindow.UIG1Window.UIG1Table; #endregion

我有一个WinTable,我想用我的测试值检查一些行的值。由于每天都会添加新行,所以行索引值是动态的,我需要找到它。我需要迭代所有行,以获得我要检查值的正确行。但是,我还不能迭代表中的所有行

        #region Variable Declarations
        WinTable uIG1Table = this.UIProMANAGEWindow.UIMouldOperationWindow.UIG1Window.UIG1Table;
        #endregion
        Assert.AreEqual(this.OperationListTableControl1ExpectedValues.UIG1TableControlType, uIG1Table.ControlType.ToString());
当我有行索引时,我可以使用GetRow更正行

        WinRow dataGridrow = uIG1Table.GetRow(1);
        MessageBox.Show(dataGridrow.RowIndex.ToString());
当我没有行索引时,我需要迭代,但我不能循环所有行,代码永远不会进入foreach循环

        UITestControlCollection rows = uIG1Table.Rows;

        foreach (WinRow row in uIG1Table.Rows)

        {

            MessageBox.Show(row.RowIndex.ToString());
            foreach (WinCell cell in row.Cells)

            {
                MessageBox.Show(cell.Value);
            }
我还尝试将行作为数组进行排序,但没有成功

       // MessageBox.Show(rows[5].RowIndex.ToString());

如果rows集合中没有行,它将不会进入for循环。 因此,您应该检查集合的行数

您完全可以通过获取WinTable的子项来迭代WinTable。 UitestcontrolCollection rows=WinTable.GetChildren,然后将其放入for循环

但是,如果表和行之间有另一个控件,则需要检查层次结构。

问答可能会有所帮助。它是关于WPF应用程序的,但是对于winforms控件,“GetChildren”方法也应该是可访问的。答案描述了如何迭代控件并递归返回给定父级的所有子级。您可能需要稍微调整代码以满足您的需要。