如何按模型访问量角器中项目级别的输入 [英] How to access input at item level in protractor by model

查看:54
本文介绍了如何按模型访问量角器中项目级别的输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无法通过模型访问量角器的角度输入

已经通过post

<!--我可以访问跨度--><span>{{todo.text}}</span><span>{{todo.address}}</span><span>{{todo.done}}</span><!--我无法访问输入--><input type="text" ng-model="todo.text"/><input type="text" ng-model="todo.address"/><input type="text" ng-model="todo.done"/>

Protractor Javasript 我可以在项目级别访问 Span 但无法访问 Input

var 结果=browser.findElements(protractor.By.repeater('todo in todos').column('todo.text'));/*对于项目级别的跨度它有效*//*结果.然后(功能(arr){arr[0].getText().then(function(text) {console.log(": "+ text);});});*/

对于项目级别的输入它不起作用

尝试1:typeError:无法调用未定义的方法'getText'

/*结果.然后(函数(arr){arr[0].getText().then(function(text) {console.log(": "+ text);//TypeError: 无法调用未定义的方法getText"});});*/

尝试 2 : typeError : 无法调用未定义的方法

如何访问模型根据

量角器如何访问模型

result.then(function(arr) {arr[0].then(函数(文本){console.log(": "+ text.getAttribute('value'));});});

无法找到我做错了什么..还有其他方法可以访问 Angular 输入吗.

解决方案

在尝试了很长时间后,我终于成功了:

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));结果.然后(函数(arr){/*获取文本*/var m = arr.all(by.model("todo.text")).getAttribute('value');m.then(函数(l){控制台日志(l);});/*清除文本*/arr.all(by.model("todo.text")).clear();/*设置文本*/arr.all(by.model("todo.text")).sendKeys('Hello');});};});

疑问:

  1. 我知道 Angular promise..then .我嵌套了三个 Angular promise..then 一个在另一个里面,但不知道为什么要使用 then 在量角器中.
  2. 在evaluate"下面只返回 itemcount.

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.

解决方案

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.

这篇关于如何按模型访问量角器中项目级别的输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆