2016-04-18 7 views
1

以内に私は次のようになりますHTMLとAngularJSアプリテストしてい:私はリピーター本部のテキストの内容に基づいて、入れ子にはい/いいえのボタンを見つけることしようとしていますC#分度器 - ファインディング要素別の要素

<div class="ng-scope" ng-repeat="something in section.questions"> 
... 
</div> 
<div class="ng-scope" ng-repeat="something in section.questions"> 
... 
</div> 
<div class="ng-scope" ng-repeat="something in section.questions"> 
      <div ng-switch="something.visible"> 
       <div id="Ins_Othersumarea" class="content-detail-wrap ng-scope ng-isolate-scope" ng-switch-when="true" highlight="something.code == global.highlightedQuestionCode" highlightedcode="global.highlightedQuestionCode" ng-dblclick="logObject(something)">       
        <div ng-class="{divider: showDivider(section, $index)}">                      
         <div ng-switch="something.type" class="content-detail-section">                 
          <div class="ng-scope" ng-switch-when="TRIGGER_YES"> 
           <ng-include class="ng-scope" src="getFragment('yes-no-fragment.html')" ng-if="!global.interview.isGroup" ng-init="baseQuestion = something"> 
          <div class="row ng-scope"> 
           <div class="col-sm-6" ng-switch="baseQuestion.answerValue == undefined &amp;&amp; !global.readonly"> 
            <div class="content-detail-right ng-scope" ng-switch-when="true"> 
             <div class="row"> 
              <div class="col-xs-6"> 
               <button type="button" id="yes_Ins_Other sum area" class="btn-base-question-triggers ng-binding" ng-click="answerbaseQuestion(baseQuestion, true)" tabindex="1" setfocus="Ins_Other sum area">Yes</button> 
              </div> 
              <div class="col-xs-6"> 
               <button type="button" id="no_Ins_Other sum area" class="btn-base-question-triggers ng-binding" ng-click="answerbaseQuestion(baseQuestion, false)" tabindex="1">No </button> 
              </div> 
             </div> 
            </div> 
           </div> 
          </div> 
... 

を。

私は右NGリピート要素を見つけることができます - 私は、適切なはい/いいえボタンをつかむしないための方法を理解することはできませんしかし

var repeatElement = NgDriver.FindElements(NgBy.Repeater("something in section.questions")).First(x => x.Text.Contains("Some Text")); 

..

私が試した -

repeatElement.FindElement(By.XPath("//button[contains(.,'Yes')]")) 

しかし、これは最初の "はい"ボタンをページに返します(期待していたようにng-repeat部門の中にはありません)。

  1. なぜですか?
  2. 私は何をしようとしていますか?
+0

あなたは 'repeatElement'が正しい要素であると確信していますか? 'repeatElement'の内部HTMLをまだ見ていないのですか? – Buaban

+0

@Buaban repeatElementがTextプロパティに基づいて正しいことがわかります。私があなたが示唆するようにしてきたにもかかわらず、それは確かに正しいように見える。 –

答えて

3

repeatElement.FindElement(By.XPath("//button[contains(.,'Yes')]"))

これは、XPath式が特定のコンテキスト/ repeatElementことがドットで開始しなければならないことを除いて、ほぼ正しい:

repeatElement.FindElement(By.XPath(".//button[contains(.,'Yes')]")) 
0
var yesButton = repeatElement.FindElement(By.Id("yes_Ins_Other")); 

又は

var yesButton = repeatElement.FindElements(By.Tag("button")).FirstOrDefault(x => x.GetAttribute("id") == "yes_Ins_Other"); 
関連する問題