我正在使用看起来像这样的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 && !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>
...
我正在尝试根据转发器Div文本内容找到嵌套的“是/否”按钮。
我可以通过 -
找到正确的ng-repeat元素var repeatElement = NgDriver.FindElements(NgBy.Repeater("something in section.questions")).First(x => x.Text.Contains("Some Text"));
但是我无法找到合适的是/否按钮..
我试过了 -
repeatElement.FindElement(By.XPath("//button[contains(.,'Yes')]"))
但是这会返回第一个&#34;是&#34;按钮在页面上(而不是像我期望的那样在ng-repeat Div内部)。
答案 0 :(得分:3)
repeatElement.FindElement(By.XPath("//button[contains(.,'Yes')]"))
这几乎是正确的,除了XPath表达式必须以点开头是特定于上下文/ repeatElement
:
repeatElement.FindElement(By.XPath(".//button[contains(.,'Yes')]"))
答案 1 :(得分: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");