[英]C# get first row from a dynamic table
I have created this method to get data from a dynamic table.我创建了这个方法来从动态表中获取数据。 However, I want to just get the top row each time I call this method.
但是,每次调用此方法时,我只想获得第一行。 I am unable to find a solution
我无法找到解决方案
Basically in the below code, I want to return tablerow[0] of the result基本上在下面的代码中,我想返回结果的 tablerow[0]
public static Dictionary<string, IWebElement> GetlatestResults(String GridPath, String GridPathHeader)
{
var Result = new Dictionary<string, IWebElement>();
var workflowtable = DriverContext.Driver.FindElement(By.XPath(GridPath));
IList<IWebElement> tableRow = workflowtable.FindElements(By.TagName("tr"));
var workflowTableHeader = DriverContext.Driver.FindElement(By.XPath(GridPathHeader));
IList<IWebElement> colElements = workflowTableHeader.FindElements(By.TagName("th"));
//int rowIndex = 0;
foreach (var row in tableRow)
{
int headerValueIndex = 0;
IList<IWebElement> rowValues = row.FindElements(By.TagName("td"));
foreach (var rowValue in rowValues)
{
Result.Add(colElements[headerValueIndex].Text, rowValue);
headerValueIndex++;
}
//rowIndex++;
};
return Result;
}
Try this尝试这个
var row = tableRow.First();
int headerValueIndex = 0;
IList<IWebElement> rowValues = row.FindElements(By.TagName("td"));
foreach (var rowValue in rowValues)
{
Result.Add(colElements[headerValueIndex].Text, rowValue);
headerValueIndex++;
}
Skip the foreach
altogether.完全跳过
foreach
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.