【发布时间】:2022-12-03 07:04:59
【问题描述】:
// elements is of type ReadOnlyCollection<IWebElement>
var elements = Context.Driver.FindElements(By.XPath(path));
// sortedElements is of type OrderedEnumerable<IWebElement, int>
var sortedElements = elements.OrderBy(a => a.point.Y); // a.point.Y is a Point object (so ordering by int)
// inspecting sortedElements here produces the correct sorting by a.point.Y
foreach (var row in sortedElements.ToList()) {
System.Console.WriteLine(row.point.Y);
// here, the rows are no longer in sorted order even though sortedElements is sorted?
// i.e., row.point.Y's are not being logged with correct sorting
}
我尝试将元素转换为 .ToList() 或 .ToArray()(与 sortedElements 相同)。令我感到困惑的是,为什么 sortedElements 是明确排序的,但是当我枚举它时,枚举是以未排序的顺序发生的。我认为 ToList() 应该保持秩序..有谁知道这里可能发生了什么?
【问题讨论】: