【问题标题】:Protractor: TypeError: Cannot call method 'click' of undefined量角器:TypeError:无法调用未定义的方法“单击”
【发布时间】:2015-03-28 14:19:56
【问题描述】:

当前在尝试找出以下元素在尝试单击时抛出错误“TypeError: Cannot call method 'click' of undefined”时遇到问题。

browser.driver.sleep(2000);

// Undefined, figure out why it cant get a hold of this
expect(element.all(by.css('[ng-value="account.id"]')).get(0).isPresent()).toBe(true);

element.all(by.css('[ng-value="account.id"]')).get(0).then(function (elm) {
    browser.driver.sleep(1000);
    elm[0].click();
});

正在查看的元素如下(有多个元素,这就是为什么我调用“.get(0)”来查看它们集中的第一个单选按钮):

<div class="row row-center" style="height: 85%;">
       <div class="col">
         <div class="list card" ng-if="accounts != null">
            <div class-="list">
                <label class="item item-radio"
                       ng-repeat="account in accounts" ng-if="account.clippable && account.fundable">
                    <input type="radio"
                           ng-model="accountConnection.id"
                           ng-value="account.id" >
                    <div class="item-content">
                        {{ account.meta.name }} ({{ account.meta.number }})
                        <p>${{ account.balance.current }}</p>

                    </div>
                    <i class="radio-icon ion-checkmark"></i>
                </label>
            </div>
        </div>
    </div>
</div>

【问题讨论】:

  • 你为什么使用elm[0].click()?如果你改用elm.click() 会发生什么?您能否验证elm 是否包含您要查找的控件?
  • 如果我改用“elm.click()”,我会收到错误:ElementNotVisibleError: element not visible.
  • 我有一个期望(element.all(by.css('[ng-value="account.id"]')).get(0).isPresent()).toBe(true );在我尝试调用点击的正上方,它没有出错,所以我认为这意味着该元素是可见的。
  • 只是为了验证发生了什么,您可以在点击前添加browser.sleep(1000);吗?这显然不是一个永久的解决方案,但它应该会提示您页面仍未完成加载。
  • 我用我已经准备好的睡眠更新了原始评论,我只是在点击之前添加了你提到的睡眠。仍然返回同样的问题。

标签: angularjs protractor e2e-testing


【解决方案1】:

将 sn-p 更改为:

element.all(by.css('[ng-repeat="account in accounts"]')).then(function (elm) {
    elm[0].click();
});

而且它现在似乎工作正常。

【讨论】:

    猜你喜欢
    • 2015-12-23
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多