Visual studio 2012 如何根据搜索到的InnerText/Name知道控件ID
场景u_;当我从网格中选择一个项目时生成的上述代码。我注意到项目在网格中被标识为“窗格”。现在对于不同的场景,我必须选择不同的项目。我所有的输入值都存储在一个文件中,从中我提取一个值并传递给测试方法 我想要什么?我需要根据我提供的值找到网格的行id,以便鼠标单击该行 我所做的是,用从数据库检索的数据填充网格。所以我不能假设哪个值将具有什么行id。我更改了InnerText SearchProperty,但播放停止,测试失败 我注意到HTML中的HTML结构是这样的Visual studio 2012 如何根据搜索到的InnerText/Name知道控件ID,visual-studio-2012,automated-tests,coded-ui-tests,Visual Studio 2012,Automated Tests,Coded Ui Tests,场景u_;当我从网格中选择一个项目时生成的上述代码。我注意到项目在网格中被标识为“窗格”。现在对于不同的场景,我必须选择不同的项目。我所有的输入值都存储在一个文件中,从中我提取一个值并传递给测试方法 我想要什么?我需要根据我提供的值找到网格的行id,以便鼠标单击该行 我所做的是,用从数据库检索的数据填充网格。所以我不能假设哪个值将具有什么行id。我更改了InnerText SearchProperty,但播放停止,测试失败 我注意到HTML中的HTML结构是这样的 public class UI
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
}
请给出一些解决方案…我没有发现任何线索
感谢您抽出时间……我将重构您的代码。您已经在HTML中获得了行的Id,所以让我们使用它。TestBuilder倾向于使内容更难阅读,并且包含太多属性,使搜索变得高效或有意义 因此,.uitest文件有两个子类:.designer.cs(上面的代码所在的位置)和.cs文件。打开.cs文件并通过执行以下操作定位行:
<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>
然后,在测试中,如果要获取某一行,只需调用myMap.gridRow2来获取该特定行的HtmlDiv
然后,如果在该行中有超链接,则在地图中创建对象:
public HtmlDiv gridRow(int index)
{
HtmlDiv target = new HtmlDiv(browser);
target.SearchProperties.Add(HtmlDiv.PropertyName.Id, "gridRow" + index.ToString());
return target;
}
不过,如果您想使用innerText,只需将PropertyName.Id更改为PropertyName.innerText并使用其值即可。您可以迭代网格中的所有行,并将其保存到提供的值-当找到匹配项时,将其作为控件传递给鼠标。单击control方法。要获取控件,请在网格控件上使用GetChildren方法。。。根据您的建议,我使用此公共HtmlDiv gridRowstring innerText,UITestControl浏览器{HtmlDiv target=new HtmlDivbrowser;target.SearchProperties.AddHtmlDiv.PropertyNames.innerText,innerText;return target;}公共字符串RowIdHtmlDiv HtmlDiv{string rowID=HtmlDiv.GetPropertyId.ToString;return rowID;}谢谢…很高兴它成功了!如果您满意,请标记答案:
public HtmlHyperlink linkOnRow(int index)
{
HtmlHyperlink target = new HtmlHyperlink(gridRow(index));
target.SearchProperties.Add(HtmlHyperlink.PropertyNames.[your prop], [your value]);
return target;
}