简体   繁体   English

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

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

So I have this LISTVIEW for example 所以我有这个LISTVIEW例如

listStudents: listStudents:

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

This list view is from a third party app and I don't have the source code. 该列表视图来自第三方应用程序,我没有源代码。

what I need is to get the complete row for example: 1 Harry Potter 13 Hogwarts 我需要的是完整的行,例如:1哈利·波特13霍格沃茨

I use inspect to get the IDs. 我使用检查来获取ID。 And I am using teststack. 我正在使用测试堆栈。

this is the code I've tried: 这是我尝试过的代码:

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

the problem is, it only returns the 1st column of the row, which is the id. 问题是,它仅返回该行的第一列,即id。 for example in the first row: 1 例如在第一行:1

I checked the inspect and it shows: 我检查了检查,它显示:

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

is there anyway to get these values? 反正有这些值吗?

The Items property returns a collection of the first columns text here is the code from white. Items属性返回第一列文本的集合,此处是白色代码。

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

So you would want to use the rows proeprty instead. 因此,您可能想改用proeprty行。

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

This also support using index of the cell. 这也支持使用单元格的索引。

 listView.Rows[0].Cells[0]

Here is the example from the unit test I based my answer off of. 这是我根据答案得出的单元测试示例。

 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