量角器 - 等待多个元素 [英] Protractor - Wait for multiple elements

查看:97
本文介绍了量角器 - 等待多个元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试等待页面上的多个元素,我不知道会有多少元素,但至少会有一个元素。我理解使用以下内容等待单个元素,效果很好。

I am trying to wait for multiple elements on the page, I don't know how many there could be but there will be at least one. I understand waiting for a single element using the following, which works fine.

var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(element(by.css("h3[title='Test Form']"))), 10000);
    expect(element(by.css("h3[title='Test Form']")).isPresent()).toBeTruthy();

我想稍微改变一下等待多个元素,所以尝试了下面的内容(添加.all到元素)。

I wanted to change this slightly to wait for multiple elements and so tried the below (adding .all to element).

var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceOf(element.all(by.css("h3[title='Test Form']"))), 10000);
    expect(element.all(by.css("h3[title='Test Form']")).isPresent()).toBeTruthy();

不幸的是,当我尝试这个时,我得到了

Unfortunately when I try this I get

Cannot read property 'bind' of undefined

任何帮助非常感谢。

ps Protracor的新手及其怪癖。

p.s. Newbie to Protracor and its quirks.

推荐答案

presenceOf 需要单个元素 ElementFinder )要传入。

您需要等待的自定义预期条件。如果我理解正确,你需要等到N个元素存在。以下是如何做到这一点:

You would need a custom Expected Condition to wait for. If I understand you correctly, you need to wait until N elements are present. Here is how you can do it:

function waitForCount (elementArrayFinder, expectedCount) {
    return function () {
        return elementArrayFinder.count().then(function (actualCount) {
            return expectedCount === actualCount;  // or <= instead of ===, depending on the use case
        });
    };
};

用法:

var forms = element.all(by.css("h3[title='Test Form']"));
browser.wait(waitForCount(forms, 5), 10000);

这篇关于量角器 - 等待多个元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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