[英]Getting an IEnumerable of all values in a certain column
I'm currently working with the Atata framework and using a Kendo grid.我目前正在使用 Atata 框架并使用 Kendo 网格。 What I'm trying to achieve is getting an IEnumerable or a collection containing all the values in a column.
我想要实现的是获取一个 IEnumerable 或一个包含列中所有值的集合。 The kendo grid is defined as below:
剑道网格定义如下:
public KendoGrid<TransactionGroupsRow, _> TransactionGroupsGrid { get; private set; }
public class TransactionGroupsRow : KendoGridRow<_>
{
[FindByColumnHeader("Group Name")]
public Link<_> GroupName { get; private set; }
}
I not only want a collection of all the links GroupName, I specifically want the text component of them ie what the link would read like on the screen.我不仅想要所有链接 GroupName 的集合,我还特别想要它们的文本组件,即链接在屏幕上的显示内容。
So in this example I would want an IEnumerable containing "002999" and "003999".所以在这个例子中,我想要一个包含“002999”和“003999”的IEnumerable。
Let me know if I need to provide additional detail.让我知道是否需要提供更多详细信息。 Thanks in advance!
提前致谢!
There are 2 ways to do that.有两种方法可以做到这一点。
Use SelectData
method.使用
SelectData
方法。 It works quite fast for list of items with count <= 50.它适用于计数 <= 50 的项目列表。
// Just get all items: IEnumerable<string> groupNames = page.TransactionGroupsGrid.Rows.SelectData(x => x.GroupName.Content.Value).Value; // Assert items: page.TransactionGroupsGrid.Rows.SelectData(x => x.GroupName.Content.Value).Should.Contain("002999", "003999");
The faster way is using SelectContentsByExtraXPath
method.更快的方法是使用
SelectContentsByExtraXPath
方法。 This one will work very fast even for a table with 1000 rows.即使对于有 1000 行的表,这个也可以非常快地工作。 But you need to specify a relative XPath to the table cell
td
element inside a row tr
element.但是您需要为行
tr
元素内的表格单元格td
元素指定相对 XPath 。 This can also be extracted to the page object class as a method.这个也可以提取到页面object class作为方法。
// Just get all items: IEnumerable<string> groupNames = page.TransactionGroupsGrid.Rows.SelectContentsByExtraXPath("td[1]", "Group Names").Value; // Assert items: page.TransactionGroupsGrid.Rows.SelectContentsByExtraXPath("td[1]", "Group Names").Should.Contain("002999", "003999");
You can also check Performance Practices for ControlList Atata sample project.您还可以查看ControlList Atata 示例项目的性能实践。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.