2017-01-31 7 views
0

로 이동 나는 각 행은 확장 된 첫 번째 행과 같은 구문을 포함하는 다음과 같은 HTML을특정 클래스의 모든 요소를 ​​얻기 플러스 앞뒤로 CodedUI

`<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")을 얻은 다음 부모 행으로 이동하여 Agree/Disagree 라디오 버튼 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에 액세스 할 수 없습니다.

마지막으로 다루는 항목은 특정 행에 대한 참조를 유지하면서 앞뒤로 탐색하는 방법일까요?

+0

다음 HtmlSpan theAnswer = (HtmlSpan) 답변을 수행하여 텍스트 문제를 해결했습니다. Debug.WriteLine (theAnswer.InnerText); '그러나 참조를 유지하면서 요소를 탐색하는 방법은 아직 약간 분실 상태입니다. –

답변

1

이것은 실제로 매우 멋진 질문입니다. 코드화 된 UI에서 DOM의 모든 요소에는 단일 부모와 자식 콜렉션이 있음을 기억하십시오. 한마디로

, 당신이하고 싶은 것 것은 :

  • 클래스 = "대답"에 처음 HtmlSpan를 찾아, 각 행의 각 행에
  • 을 통해
  • 으로 반복 테이블 컨트롤 만들기 . 이것을 HtmlSpans 컬렉션에 추가하십시오.
  • 이 모음집이 있으면이 모음집을 다시 한 번 반복 할 수 있습니다. 거기에서 속성을 기반으로 "형제 제어"를 가져 오는 도우미 메서드를 만드는 것이 좋습니다. 이 메서드는 부모 컨트롤의 자식 컬렉션을보고 거기에서 요소를 가져옵니다. 테이블의 각 행을 반복하면서 그냥 정답을 선택할 수없는 경우

마지막 단계는 필요하다. 내 책에서 나는 차라리 : 각 행

  • 통해

    • 반복 처리가 응답 요소와이 올바른 라디오 버튼을 선택하여 정답을 선택하는 자사의 내부 텍스트
    • 를 사용하여 내부 텍스트 찾기 같은 행 (나는 이것이 데이터 구동이라고 가정).

    의미가 있습니까? 이 정보가 도움이되는지 또는 더 자세한 정보가 필요한지 알려주십시오. 나는 도우미 메소드 코드를 가지고 있지 않지만 매우 간단하다. 예 :

    public static UiTestControl GetSiblingByClass (UiTestControl ctrl, string class) { 
        var parent = ctrl.Parent; 
        var controlToReturn = new UiTestControl(parent); 
        controlToReturn.SearchProperties[HtmlControl.PropertyNames.Class] = class; 
        return controlToReturn; 
    } 
    
  • +0

    응답 해 주셔서 감사합니다. 나는 이것을 시도해보고 내가 생각해내는 것을 알려 줄 것이다. –