How to access input at item level in protractor by model

痴心易碎 提交于 2019-12-22 00:39:23

问题


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 :

  1. I know about Angular promise..then .i have nested three Angular promise..then one inside another but don't know why use then in protractor.
  2. Below "evaluate" just returns itemcount.


来源:https://stackoverflow.com/questions/27227195/how-to-access-input-at-item-level-in-protractor-by-model

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!