请有人帮我找到动态元素,并使用量角器将值发送到该元素。
这是我的PurchaseInfo.html代码段,其中输入字段动态加载到页面上:
<div class="row subpage-submit-flow">
<div class="col-md-12">
<!-- progress bar -->
<uib-progressbar value="45" class="in-progress"></uib-progressbar>
<!-- end progress bar -->
<div class="page-header">
<h2 id="purchaseInfo-header" translate="content.PURCHASE_INFO_HEADER"></h2>
<p id="purchaseInfo-reqFieldLbl" translate="content.PURCHASE_INFO_REQUIRED_FIELD_LABEL"></p>
</div>
<div class="row">
<div class="col-md-12">
<p ng-show="purchaseInfo.$invalid" class="error-message pull-right">
*Please complete all required fields.
</p>
</div>
</div>
<div class="clearfix"></div>
<div class="row">
<div ng-class="purchaseInfoCtrl.receiptImage ? 'col-md-6' : 'col-md-12'">
<form name="purchaseInfo" novalidate>
<div ng-if="webAttributes" class="row">
<div ng-repeat="webAttribute in webAttributes track by $index">
<div class="clearfix" ng-if="$index % 2 == 0"></div>
<div ng-class="purchaseInfoCtrl.receiptImage ? 'col-md-12' : 'col-md-6'">
<div ng-if="purchaseInfoCtrl.isTextField(webAttribute) || purchaseInfoCtrl.isCurrencyField(webAttribute)"
class="form-group">
<p class="noMargin"
ng-show="purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$viewValue || webAttribute.focused"
ng-class="(purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$invalid && purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$dirty) ? 'input-error-label' : (webAttribute.focused) ? 'activeFieldLabel' : 'inactiveFieldLabel'">
<span>{{ webAttribute.displayValue }}</span>
</p>
<input id="{{ webAttribute.name }}" border-color ng-if= "webAttribute.webAttributeType == 'C'" ng-focus="purchaseInfoCtrl.focus($event)"
ng-blur="purchaseInfoCtrl.blur($event)"
ng-class="purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$dirty && purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$invalid ? 'input-error' : ''"
class="noBorderTextBox" type="text" class="form-control noBorderTextBox" name="{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}"
ng-model="purchaseInfoCtrl.model.attributes[webAttribute.webAttributeIndex].value"
placeholder="{{ webAttribute.displayValue }}"
ng-required="webAttribute.mandatory"
ng-pattern="/^[^<%>\\\\]+$/">
<input id="{{ webAttribute.name }}" border-color ng-if= "webAttribute.webAttributeType == 'P'" ng-focus="purchaseInfoCtrl.focus($event)"
ng-blur="purchaseInfoCtrl.blur($event)"
ng-class="purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$dirty && purchaseInfo.{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}.$invalid ? 'input-error' : ''"
class="noBorderTextBox" type="text" class="form-control noBorderTextBox" name="{{webAttribute.webAttributeType}}{{webAttribute.webAttributeIndex}}"
ng-model="purchaseInfoCtrl.model.product.attributes[webAttribute.webAttributeIndex].value"
placeholder="{{ webAttribute.displayValue }}"
ng-required="webAttribute.mandatory"
ng-pattern="/^[^<%>\\\\]+$/">
</div>
我正在遵循页面对象模式,并且在我的PurchaseInfo-pageObject.js类中,我已经在下面的函数中编写了此函数,并从PurchaseInfo_spec.j调用了它。令人惊讶的是,sendKeys无法正常工作,但在控制台中已打印出dispalyed&sendvalues。请帮助我。我会很感激的。提前致谢。
this.inputFieldsAll = function (){
this.inputElems = element.all(by.repeater('webAttribute in webAttributes track by $index')).get(1);
if (this.inputElems.isDisplayed()){
this.inputElems.sendKeys('764763688888');
console.log('dispalyed&sendvalues');
}
this.inputElems.getText().then(function(val){
console.log('value: ',val);
});
最佳答案
首先,当前代码中存在一个主要问题:
if (this.inputElems.isDisplayed()) {
isDisplayed()
返回一个总是“真实”的承诺,因此,无论实际的显示状态如何,条件始终为true。另一个问题与您要将密钥发送到哪个元素有关。当前,您正在将密钥发送到与转发器匹配的
div
元素。相反,您需要找到内部的input
元素:var inputs = element.all(by.repeater('webAttribute in webAttributes')).get(1).all(by.tagName("input"));
inputs.first().sendKeys("764763688888");