我有以下 HTML
`<table id="tableRepeat44" class="scaledTableGroup">
<tbody>
<tr>
<tr class="grpTableRegRow">
<td class="borderCell" title="Strongly Disagree">
<input id="QID16108TAG1" value="1" name="QID16108TAG" type="radio">
<td class="borderCell" title="Disagree">
<input id="QID16108TAG2" value="2" name="QID16108TAG" type="radio">
<td class="borderCell" title="Somewhat Disagree">
<input id="QID16108TAG3" value="3" name="QID16108TAG" type="radio">
<td class="borderCell" title="Somewhat Agree">
<input id="QID16108TAG4" value="4" name="QID16108TAG" type="radio">
<td class="borderCell" title="Agree">
<input id="QID16108TAG5" value="5" name="QID16108TAG" type="radio">
<td class="borderCell" title="Strongly Agree">
<input id="QID16108TAG6" value="6" name="QID16108TAG" type="radio">
<td class="questionColumn">
<span id="lblsubq16108_7" class="Answer">This is a question. </span>
</td>
</tr>
<tr class="grpTableAltRow">
<tr class="grpTableRegRow">
<tr class="grpTableAltRow">
</tbody>
</table>`
每行包含与展开的第一行相同的语法。我希望通过 CodedUI 做的是获取所有问题的文本(例如 td:nth-of-type(7) > span || class="Answer"),然后导航到父行,以便我可以访问同意/不同意单选按钮 tds 并根据传入的参数进行选择。
我已经尝试过
HtmlCustom questionsTable = new HtmlCustom(browser);
HtmlControl controls = new HtmlControl(questionsTable);
if (howToAnswer.Trim().ToLower() == "correct")
{
questionsTable.SearchProperties[HtmlCustom.PropertyNames.TagName] = "Tbody";
controls.SearchProperties.Add(HtmlControl.PropertyNames.Class, "Answer");
UITestControlCollection collection = controls.FindMatchingControls();
foreach (UITestControl answers in collection)
{
Debug.Write(answers);
}
}
它导致ControlType [Pane] ClassName [HtmlPane] TagName [SPAN], UniqueIdentifier [154] Id [lblsubq16172_7] Name []
表格中的每一行。所以我很接近,但我无法弄清楚如何获取.InnerText
无法访问的文本answers
。
最后要解决的问题是如何在保持对特定行的引用的同时来回导航?