如何根据搜索到的控件 ID InnerText/Name

How to know control ID based on searched InnerText/Name

public class UIRow0jqxGrid1Pane : HtmlDiv
    {

        public UIRow0jqxGrid1Pane(UITestControl searchLimitContainer) : 
                base(searchLimitContainer)
        {
            #region Search Criteria
            this.SearchProperties[HtmlDiv.PropertyNames.Id] = "row0jqxGrid1";//This ID will be dynamic. Need to search based on provided InnerText
            this.SearchProperties[HtmlDiv.PropertyNames.Name] = null;
            this.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "XXXX";
            this.FilterProperties[HtmlDiv.PropertyNames.Title] = null;
            this.FilterProperties[HtmlDiv.PropertyNames.Class] = null;
            this.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "id=\"row0jqxGrid1\" role=\"row\" style=\"height: 25px; ;\"";
            this.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "696";
            this.WindowTitles.Add("Test");
            #endregion
        }

        #region Properties
        public HtmlDiv UIALMONDESTATECONSULTAPane
        {
            get
            {
                if ((this.mUIALMONDESTATECONSULTAPane == null))
                {
                    this.mUIALMONDESTATECONSULTAPane = new HtmlDiv(this);
                    #region Search Criteria
                    this.mUIALMONDESTATECONSULTAPane.SearchProperties[HtmlDiv.PropertyNames.Id] = null;
                    this.mUIALMONDESTATECONSULTAPane.SearchProperties[HtmlDiv.PropertyNames.Name] = null;
                    this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.InnerText] = "XXXX";
                    this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.Title] = null;
                    this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.Class] = null;
                    this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.ControlDefinition] = "style=\"text-align: left;  padding-bottom: 2px; margin- " +
                        "margin-right: 2px; margin- -ms-text-\"";
                    this.mUIALMONDESTATECONSULTAPane.FilterProperties[HtmlDiv.PropertyNames.TagInstance] = "700";
                    this.mUIALMONDESTATECONSULTAPane.WindowTitles.Add("Test;
                    #endregion
                }
                return this.mUIALMONDESTATECONSULTAPane;
            }
        }
        #endregion

        #region Fields
        private HtmlDiv mUIALMONDESTATECONSULTAPane;
        #endregion
    }

场景____ 当我select 来自网格的项目时生成以上代码。我注意到项目在网格中被标识为 'Pane'。现在对于不同的场景,我必须 select 不同的项目。我所有的输入值都存储在一个文件中,我从中提取一个值并传递给测试方法。

我想要的 ____ 我需要根据我提供的值找到网格的行 ID,以便鼠标单击发生在该行上。

我做了什么 ____ 网格填充了从数据库检索的数据。所以我不能假设哪个值会有什么行 ID。我更改了 InnerText SearchProperty,但随后播放停止并且测试失败。

我在HTML中注意到____HTML结构是这样的

<grid id="grid1" style="....">
  <div>Header Row definition</div>
  <div> Data Row
    <div id="gridRow0" style="...">A</div>
    <div id="gridRow1" style="...">B</div>
    <div id="gridRow2" style="...">C</div>
    <div id="gridRow3" style="...">D</div>
    .......
    ......
  </div>
</grid>

请给出一些解决方案...我没有找到任何线索...

感谢您的宝贵时间...

我会重构你的代码。您已经在 HTML 中获得了该行的 ID,所以让我们使用它。 TestBuilder 往往会使事情变得有点难以阅读,并且包含太多属性,无法使搜索高效或有意义。

因此,您的 .uitest 文件有两个子 类:.designer.cs(上面的代码所在的位置)和一个 .cs 文件。打开 .cs 文件并通过执行以下操作找到您的行:

public HtmlDiv gridRow(int index)
{
     HtmlDiv target = new HtmlDiv(browser);
     target.SearchProperties.Add(HtmlDiv.PropertyName.Id, "gridRow" + index.ToString());
     return target;
}

然后,在您的测试中,如果您想要获取某一行,只需调用 myMap.gridRow(2) 即可获取该特定行的 HtmlDiv。

然后,如果您有一个超链接,例如,在您的地图的该行中,您将创建对象:

public HtmlHyperlink linkOnRow(int index)
{
    HtmlHyperlink target = new HtmlHyperlink(gridRow(index));
    target.SearchProperties.Add(HtmlHyperlink.PropertyNames.[your prop], [your value]);
    return target;
}

不过,如果您想使用 innerText,只需将 PropertyName.Id 更改为 PropertyName.InnerText 并改用它的值即可。