在量角器中,如何检查aria-hidden =“ true”或“ false”

时间:2019-08-23 12:36:52

标签: javascript selenium protractor

我需要根据点击次数来检查 aria-hidden =“ true”或“ false”

 <tr ng-class="{'submitted' : (position.submitted) }" ng-repeat- 
 start="position in demandFactory.openings | orderBy:sortType:sortReverse">
                    <td><span ng-click="openDemand(position.demandID)"><span ng-show="position.demandID == demandFactory.selectedDemand">
                            <span class="glyphicon glyphicon-menu-down glyphicon-small" aria-hidden="true"></span>
                        </span>
                        <span ng-show="position.demandID != demandFactory.selectedDemand">
                            <span class="glyphicon glyphicon-menu-right glyphicon-small" aria-hidden="true"></span>
                        </span></span>
                        <span class="jobName">&nbsp{{ position.name }} </span>
                    </td>
                    <td>{{ position.demandID }}</td>
                    <td>{{ position.rotation }}</td>
                    <td>{{ position.headcount }}</td>
                    <td>{{ position.num }}</td>
                    <td>{{ position.approved }}</td>
                </tr>

在测试用例中,我已经访问了元素,但可以获取 aria-hidden 值。

  var aPromiseOfRows = element.all(by.repeater('position in demandFactory.openings').row(0).column("position.name"));
  aPromiseOfRows.getText().then(function(text) {
  console.log(text);
});

1 个答案:

答案 0 :(得分:0)

对于量角器,您可以使用here中记载的getAttributegetText()返回元素内部的文本,而不返回元素属性。

您可以这样做

  • 使用here中记载的get(index获取要测试的元素。
  • expect()内获取属性
  • 针对您的用例使用匹配器,例如toBe / toEqual

伪代码:

var aPromiseOfRow = element.all(by.repeater('position in demandFactory.openings').get(0);
expect(aPromiseOfRow.getAttribute('aria-hidden')).toEqual('true');

如果您希望访问该值以备后用,请使用类似的内容

var val;
aPromiseOfRow.getAttribute('aria-hidden').then(function(attrValue) {
   val = attrValue;
});

希望有帮助...