我在自动完成字段中输入了一个值,而我正在写一个测试,以正确填充该值。
但是我同时使用getText和getAttribute获得的结果为null或为空。
以下是我根据其他人回答的问题尝试过的3种方法,但似乎没有任何效果。
所有人都返回空值或null给我。
element(by.name("visitPurposeID")).getText().then(function(visitpurpose) {
console.log(visitpurpose);
expect(visitpurpose).toEqual('New Visit');
});
element(by.name("visitPurposeID")).getAttribute('visitpurpose').then(function(visitpurpose){
console.log(visitpurpose);
})
expect(element(by.name("visitPurposeID")).getAttribute('visitpurpose')).toBe('New Visit');
html表示元素
<div class="mat-form-field-infix"><input class="mat-input-element mat-form-field-autofill-control ng-tns-c64-611 cdk-text-field-autofill-monitored ng-pristine ng-valid ng-touched" matinput="" name="visitPurposeID" placeholder="Purpose of Visit" required="" ng-reflect-required="" ng-reflect-autocomplete="[object Object]" ng-reflect-form="[object Object]" ng-reflect-placeholder="Purpose of Visit" autocomplete="off" role="combobox" aria-autocomplete="list" aria-expanded="false" aria-haspopup="true" id="mat-input-203" aria-invalid="false" aria-required="true"><mat-autocomplete class="mat-autocomplete ng-tns-c64-611" ng-reflect-display-with="displayPurposeOfVisitFn(value)"><!----></mat-autocomplete><span class="mat-form-field-label-wrapper"><!--bindings={
"ng-reflect-ng-if": "true"
}--><label class="mat-form-field-label ng-tns-c29-619 ng-star-inserted" ng-reflect-ng-switch="true" ng-reflect-disabled="false" id="mat-form-field-label-699" for="mat-input-203" aria-owns="mat-input-203"><!--bindings={
"ng-reflect-ng-switch-case": "false"
}--><!--bindings={
"ng-reflect-ng-switch-case": "true"
}--><mat-label class="ng-tns-c64-611 ng-star-inserted">Purpose of Visit</mat-label><!----><!--bindings={
"ng-reflect-ng-if": "true"
}--><span aria-hidden="true" class="mat-placeholder-required mat-form-field-required-marker ng-tns-c29-619 ng-star-inserted"> *</span></label></span></div>
还有其他方法可以在输入字段上捕获文本吗?
答案 0 :(得分:2)
尝试以下一个
expect(element(by.name("visitPurposeID")).getAttribute('value')).toBe('New Visit');
希望对您有帮助