【发布时间】:2021-03-29 19:57:18
【问题描述】:
我创建了这个方法来从动态表中获取数据。但是,每次调用此方法时,我只想获得第一行。我找不到解决办法
基本上在下面的代码中,我想返回结果的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;
}
【问题讨论】:
-
IWebElement row0 = tableRow[0];
标签: c# .net automation