【问题标题】:C# - Get the children of a list item of a listview using teststack whiteC# - 使用 teststack white 获取列表视图的列表项的子项
【发布时间】:2016-01-12 00:59:49
【问题描述】:

例如,我有这个 LISTVIEW

列出学生:

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

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

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

我使用检查来获取 ID。我正在使用 teststack。

这是我尝试过的代码:

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

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

我检查了检查,它显示:

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

有没有办法得到这些值?

【问题讨论】:

  • 由于您有多个行/列,您必须访问整个索引行是否有意义? Items[0].ElementAt[0]?
  • @Tdorno。谢谢,我试过了,但它没有给出预期的结果。

标签: c# white-framework


【解决方案1】:

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

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

所以你会想要使用 rows 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);
     }
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多