Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#量角器-在另一个元素中查找元素_C#_Angularjs_Selenium_Protractor_Protractor Net - Fatal编程技术网

C#量角器-在另一个元素中查找元素

C#量角器-在另一个元素中查找元素,c#,angularjs,selenium,protractor,protractor-net,C#,Angularjs,Selenium,Protractor,Protractor Net,我正在测试一个带有HTML的AngularJS应用程序,其外观如下: <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="s

我正在测试一个带有HTML的AngularJS应用程序,其外观如下:

<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>
...
但是,我无法找到一种方法来抓取相应的是/否按钮

我试过-

repeatElement.FindElement(By.XPath("//button[contains(.,'Yes')]"))
但这将返回页面上的第一个“Yes”按钮(而不是像我预期的那样在ng repeat Div中)

  • 为什么
  • 我怎样才能完成我想做的事情
  • repeatElement.FindElement(By.XPath(//button[contains(,'Yes')])

    这几乎是正确的,只是XPath表达式必须以一个点开始,以作为上下文/
    repeatElement
    特定的:

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


    您确定
    repeatElement
    是正确的元素吗?您调试过查看
    repeatElement
    的内部HTML了吗?@Buaban我可以看到repeatElement的文本属性是正确的。不管怎样,我已经按照你的建议做了,而且看起来确实正确。
    repeatElement.FindElement(By.XPath(".//button[contains(.,'Yes')]"))
    
    var yesButton = repeatElement.FindElement(By.Id("yes_Ins_Other"));
    
    var yesButton = repeatElement.FindElements(By.Tag("button")).FirstOrDefault(x => x.GetAttribute("id") == "yes_Ins_Other");