ng-if inside ng-repeat in protractor testing : 无法点击基于 ng-if 的元素
ng-if inside ng-repeat in protractor testing : Not able to click on elements based on ng-if
在下方 table,我想单击第一封电子邮件或第一条推特 post 我使用量角器通过我的测试脚本收到的。
我可以使用 ng-repeat 遍历行,但是如何使用 ng-if identify/distinguish twitter/email 元素并单击第一个元素。请帮忙
enter image description here
<tr class="ng-scope" ng-class="{selected: message.channel_message_ID === selectedMessageID}" style="cursor: pointer;" pagination-id="messageList" ng-click="showMessageDetails(message);setSelectedMessageId(message.channel_message_ID,message.message_status);" ng-repeat="message in messageList | filter: message_status |filter: search | orderBy: '-date_time' | itemsPerPage: pageSize : ''">
<td class="center" data-title="Status">
</td>
<td class="center" data-title="Source">
<!-- ngIf: message.channel == 'Twitter' -->
<!-- ngIf: message.channel == 'facebook' -->
<!-- ngIf: message.channel == 'Email' -->
<div class="ng-scope" ng-if="message.channel == 'Email'">
</div>
</td>
<td class="center" data-title="Source">
<td data-title="Sender">
<td data-title="Receiver">
</tr>
<tr class="ng-scope" ng-class="{selected: message.channel_message_ID === selectedMessageID}" style="cursor: pointer;" pagination-id="messageList" ng-click="showMessageDetails(message);setSelectedMessageId(message.channel_message_ID,message.message_status);" ng-repeat="message in messageList | filter: message_status |filter: search | orderBy: '-date_time' | itemsPerPage: pageSize : ''">
<td class="center" data-title="Status">
<td class="center" data-title="Source">
<!-- ngIf: message.channel == 'Twitter' -->
<div class="ng-scope" ng-if="message.channel == 'Twitter'">
<div>
<span class="fa fa-twitter icondColor"/>
</div>
</div>
</td>
<td data-title="Sender">
<td data-title="Receiver">
</tr>
请帮我点击识别出的第一个电子邮件元素或第一个推特元素。(动态元素)
您可以通过在每个元素上应用 getAttribute() 来实现。您可以使用以下代码:
element.all(by.repeater()).each(function(ele){
ele.getAttribute('ng-if').then(function(eAttrValue){
console.log("ele attribute value is: "+eAttrValue);
if(eAttrValue.indexOf("Email")>=-1){
ele.click();//click if ele is Email only
}
});
});
在下方 table,我想单击第一封电子邮件或第一条推特 post 我使用量角器通过我的测试脚本收到的。
我可以使用 ng-repeat 遍历行,但是如何使用 ng-if identify/distinguish twitter/email 元素并单击第一个元素。请帮忙
enter image description here
<tr class="ng-scope" ng-class="{selected: message.channel_message_ID === selectedMessageID}" style="cursor: pointer;" pagination-id="messageList" ng-click="showMessageDetails(message);setSelectedMessageId(message.channel_message_ID,message.message_status);" ng-repeat="message in messageList | filter: message_status |filter: search | orderBy: '-date_time' | itemsPerPage: pageSize : ''">
<td class="center" data-title="Status">
</td>
<td class="center" data-title="Source">
<!-- ngIf: message.channel == 'Twitter' -->
<!-- ngIf: message.channel == 'facebook' -->
<!-- ngIf: message.channel == 'Email' -->
<div class="ng-scope" ng-if="message.channel == 'Email'">
</div>
</td>
<td class="center" data-title="Source">
<td data-title="Sender">
<td data-title="Receiver">
</tr>
<tr class="ng-scope" ng-class="{selected: message.channel_message_ID === selectedMessageID}" style="cursor: pointer;" pagination-id="messageList" ng-click="showMessageDetails(message);setSelectedMessageId(message.channel_message_ID,message.message_status);" ng-repeat="message in messageList | filter: message_status |filter: search | orderBy: '-date_time' | itemsPerPage: pageSize : ''">
<td class="center" data-title="Status">
<td class="center" data-title="Source">
<!-- ngIf: message.channel == 'Twitter' -->
<div class="ng-scope" ng-if="message.channel == 'Twitter'">
<div>
<span class="fa fa-twitter icondColor"/>
</div>
</div>
</td>
<td data-title="Sender">
<td data-title="Receiver">
</tr>
请帮我点击识别出的第一个电子邮件元素或第一个推特元素。(动态元素)
您可以通过在每个元素上应用 getAttribute() 来实现。您可以使用以下代码:
element.all(by.repeater()).each(function(ele){
ele.getAttribute('ng-if').then(function(eAttrValue){
console.log("ele attribute value is: "+eAttrValue);
if(eAttrValue.indexOf("Email")>=-1){
ele.click();//click if ele is Email only
}
});
});