问题
Not Able to access angular input by protractor by model
Have been through post
<div ng-repeat="todo in todos">
<!--i can access span-->
<span>{{todo.text}}</span>
<span>{{todo.address}}</span>
<span>{{todo.done}}</span>
<!--i CAN'T access input -->
<input type="text" ng-model="todo.text"/>
<input type="text" ng-model="todo.address"/>
<input type="text" ng-model="todo.done"/>
</div>
Protractor Javasript I Can access Span At Item Level But Cannot access Input
var result=
browser.findElements(protractor.By.repeater('todo in todos').column('todo.text'));
/*For Span at item level It works*/
/*
result.then(function(arr) {
arr[0].getText().then(function(text) {
console.log(": "+ text);
});
});*/
For Input at item level It dosen't works
Try 1 : typeError: Cannot call method 'getText' of undefined
/*
result.then(function(arr) {
arr[0].getText().then(function(text) {
console.log(": "+ text); //TypeError: Cannot call method 'getText' of undefined
});
});*/
Try 2 : typeError : Cannot call method then of undefined
How to access model according to
How protractor access to model
result.then(function(arr) {
arr[0].then(function(text) {
console.log(": "+ text.getAttribute('value'));
});
});
Not Able to find What Wrong I Am doing ..Is There Any other way to access Angular input.
回答1:
After trying for a long time I was able to get this working:
element(by.repeater('todos')).evaluate('todos.length').then(function(itemLength)
{
for(var i = 0 ; i < itemLength ; i++)
{
var result= element(by.repeater('todo in todos').row(i));
result.then(function(arr)
{
/*FETCH TEXT*/
var m = arr.all(by.model("todo.text")).getAttribute('value');
m.then(function(l){
console.log(l);
});
/*CLEAR TEXT*/
arr.all(by.model("todo.text")).clear();
/*SET TEXT*/
arr.all(by.model("todo.text")).sendKeys('Hello');
});
};
});
Doubts :
- I know about
Angular promise..then
.i have nested threeAngular promise..then
one inside another but don't know why usethen
in protractor. - Below "evaluate" just returns itemcount.
来源:https://stackoverflow.com/questions/27227195/how-to-access-input-at-item-level-in-protractor-by-model