繁体   English   中英

C#-使用teststack white获取listview列表项的子级

[英]C# - Get the children of a list item of a listview using teststack white

所以我有这个LISTVIEW例如

listStudents:

[ID] [NAME        ] [AGE   ][SCHOOL  ] -> Header
1     Harry Potter       13   Hogwarts
2     Draco Malfoy       13   Hogwarts

该列表视图来自第三方应用程序,我没有源代码。

我需要的是完整的行,例如:1哈利·波特13霍格沃茨

我使用检查来获取ID。 我正在使用测试堆栈。

这是我尝试过的代码:

var listItem = listStudents.Items.ElementAt(0);

问题是,它仅返回该行的第一列,即id。 例如在第一行:1

我检查了检查,它显示:

[- "1" list item          ]
  [  + "Harry Potter" text]
  [  + "13" text          ]
  [  + "Hogwarts" text    ]

反正有这些值吗?

Items属性返回第一列文本的集合,此处是白色代码。

 public virtual List<string> Items
 {
     get
     {
         return Rows.Select(listViewRow => listViewRow.Cells[0].Text).ToList();
     }
 }

因此,您可能想改用proeprty行。

 listView.Rows[0].Cells["ColumnName"]

这也支持使用单元格的索引。

 listView.Rows[0].Cells[0]

这是我根据答案得出的单元测试示例。

 void CellText()
 {
     using (var window = StartScenario("OpenListView", "ListViewWindow"))
     {
         var listView = window.Get<ListView>("ListView");
         ListViewRow first = listView.Rows[0];
         Assert.Equal("Search", first.Cells[0].Text);
         Assert.Equal("Google", first.Cells[1].Text);
         ListViewRow second = listView.Rows[1];
         Assert.Equal("Mail", second.Cells[0].Text);
         Assert.Equal("GMail", second.Cells[1].Text);
     }
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM