量角器检查元素是否被选中

时间:2015-02-18 01:16:52

标签: protractor

我有3个按钮,html是:

<label class="label-text btn btn-primary active ng-dirty ng-valid-parse" btn-radio="thisDateType.value" ng-model="controller.formData.dateType" value="disputeDate" name="dateType" ng-class="{active:thisDateType.id==controller.dateTypeSelect.radioModel.id}" ng-repeat="thisDateType in controller.dateTypeSelect.dateType">Dispute Date</label>
<!-- end ngRepeat: thisDateType in controller.dateTypeSelect.dateType -->
<label class="label-text btn btn-primary ng-dirty" btn-radio="thisDateType.value" ng-model="controller.formData.dateType" value="respondByDate" name="dateType" ng-class="{active:thisDateType.id==controller.dateTypeSelect.radioModel.id}" ng-repeat="thisDateType in controller.dateTypeSelect.dateType">Respond By Date</label>
<!-- end ngRepeat: thisDateType in controller.dateTypeSelect.dateType -->
<label class="label-text btn btn-primary" btn-radio="thisDateType.value" ng-model="controller.formData.dateType" value="slaDate" name="dateType" ng-class="{active:thisDateType.id==controller.dateTypeSelect.radioModel.id}" ng-repeat="thisDateType in controller.dateTypeSelect.dateType">SLA Date</label>
<!-- end ngRepeat: thisDateType in controller.dateTypeSelect.dateType -->

我试图断言使用以下方式选择第一个按钮:

expect(SearchPage.disputeDateButton.isSelected()).toBe(true);

然而,量角器继续评估disputeDateButton.isSelected()是否为false。我已经仔细检查了我的元素定位器xpath及其正确的一个。我这样做是对吗还是有其他方法可以使用吗?

1 个答案:

答案 0 :(得分:1)

element.all(by.repeater("thisDateType")).then(function(buttonArray) {
    expect(buttonArray[0].getAttribute('class')).toBe('label-text btn btn-primary active');
});

因为类值根据选择的内容而改变,所以我决定对其进行评估,并且它可以正常工作。