如何在量角器中定位动态输入字段并传递值
问题描述:
请有人帮助我找到动态元素并使用量角器将值发送到该元素。 这里是我的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不工作,但显示& sendvalues被打印在console.Please帮我。我会很感激。提前致谢。
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()
返回承诺这始终是“truthy”,因此条件无论是总是正确的真实的显示状态。
另一个问题与您试图发送密钥的元素有关。目前,您正在向与中继器匹配的div
元素发送密钥。相反,您需要找到内部元素input
:
var inputs = element.all(by.repeater('webAttribute in webAttributes')).get(1).all(by.tagName("input"));
inputs.first().sendKeys("764763688888");
您是否正在尝试访问第二个输入ID? –
@priya你可以附上UI的截图或描述你想要交互的元素 –