Watin:遍历 Telerik gridview 中的文本框

发布于 2025-01-03 01:04:35 字数 1090 浏览 1 评论 0原文

我目前正在为使用 Telerik ASP.Net 框架的 Web 数据输入应用程序开发一个测试框架,但遇到了拦截器。如果我在调试模式下单步执行代码,测试将找到我正在查找的文本框并输入一些测试数据,然后将该数据保存到数据库中。我遇到的问题是,当我让测试自行运行时,测试失败,表明它无法对声明的列进行细化。这是我的代码:

/*Method to enter test data into cell*/
private TableCell EditFieldCell(string columnHeader)
{
 var columnIndex = ColumnIndex(columnHeader);

 if (columnIndex == -1)
    throw new InvalidOperationException(String.Format("Column {0} not found.", columnHeader));

 return NewRecordRow.TableCells[columnIndex];
}

/*Method to return column index of column searching for*/
public int ColumnIndex(string columnHeader)
{
 var rgTable = GridTable;
 var rgCount = 0;
 var rgIndex = -1;

 foreach (var rgRow in rgTable.TableRows)
 {
      foreach (var rgElement in rgRow.Elements)
      {
       if (rgElement.Text != null)
       {
        if (rgElement.Text.Equals(columnHeader))
        {
          rgIndex = rgCount;
          break;
        }
       }
       rgCount++;
     }
 return rgIndex;
 }

我的想法是,我的嵌套 for 循环中的某些内容出现了问题,因为当我让程序运行时返回的 rgIndex 值是 -1,这告诉我 for 循环中的代码没有运行。

TIA, 比尔·扬曼

I am currently developing a testing framework for a web data entry application that is using the Telerik ASP.Net framework and have run into a blocker. If I step through my code in debug mode the test will find the text box that I am looking for and enter some test data and then save that data to the database. The problem that I am running into is that when I let the test run on it's own the test fails saying that it couldn't fine the column that was declared. Here is my code:

/*Method to enter test data into cell*/
private TableCell EditFieldCell(string columnHeader)
{
 var columnIndex = ColumnIndex(columnHeader);

 if (columnIndex == -1)
    throw new InvalidOperationException(String.Format("Column {0} not found.", columnHeader));

 return NewRecordRow.TableCells[columnIndex];
}

/*Method to return column index of column searching for*/
public int ColumnIndex(string columnHeader)
{
 var rgTable = GridTable;
 var rgCount = 0;
 var rgIndex = -1;

 foreach (var rgRow in rgTable.TableRows)
 {
      foreach (var rgElement in rgRow.Elements)
      {
       if (rgElement.Text != null)
       {
        if (rgElement.Text.Equals(columnHeader))
        {
          rgIndex = rgCount;
          break;
        }
       }
       rgCount++;
     }
 return rgIndex;
 }

My thinking is that something with my nested for loops is presenting the problem because the rgIndex value that is returned when I let the program run is -1 which tells me that the code in the for loops isn't being run.

TIA,
Bill Youngman

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

随风而去 2025-01-10 01:04:35

获取表列索引的代码。您需要传递表(在调试时验证表是否存在):

 public int GetColumnIndex(Table table,  string headerName)
    {
        ElementCollection headerElements = table.TableRows[0].Elements; //First row contains the header
        int counter = 0;
        foreach (var header in headerElements)
        {
            if (header.ClassName != null && header.ClassName.Contains(headerName)) //In this case i use class name of the header you can use the text
            {
                return counter;
            }
            counter++;
        }
        // If not found
        return -1;
    }

Code that gets the table Column index. You need to pass the Table(verify that the table exists while debug):

 public int GetColumnIndex(Table table,  string headerName)
    {
        ElementCollection headerElements = table.TableRows[0].Elements; //First row contains the header
        int counter = 0;
        foreach (var header in headerElements)
        {
            if (header.ClassName != null && header.ClassName.Contains(headerName)) //In this case i use class name of the header you can use the text
            {
                return counter;
            }
            counter++;
        }
        // If not found
        return -1;
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文