Javascript 量角器中的元件加载问题

Javascript 量角器中的元件加载问题,javascript,angularjs,protractor,Javascript,Angularjs,Protractor,我现在被量角器弄糊涂了 似乎有时我的元素会及时加载,以便下一个动作发生在它们身上,有时则不会。我猜这与它的异步性质有关 因此,无论如何,例如,有时此代码通过,有时不通过: it('should create an audience using an existing audience and should be able to filter and search for that audience', function () { page.audienceTab.click();

我现在被量角器弄糊涂了

似乎有时我的元素会及时加载,以便下一个动作发生在它们身上,有时则不会。我猜这与它的异步性质有关

因此,无论如何,例如,有时此代码通过,有时不通过:

it('should create an audience using an existing audience and should be able to filter and search for that audience', function () {
        page.audienceTab.click();
        $('.panel-list .row .panel-list-header .btn').click();
        $('.panel-list div .btn').click();
        $('.edit-audience .row .col-md-3 accordion .panel-group .name-filter .panel-collapse .panel-body section input').sendKeys('test-audience');
        $('.expose-offset button').click();
        $('.col-xs-4 input').sendKeys('test-audience');
        expect($('.panel-list .panel h3').getText()).toEqual('test-audience');
    });

无论如何,这是可以修复的,这样就可以保证在触发下一个操作之前加载元素了?

有时,在.then()函数中包装最终的expect时,它会有所帮助,例如:

$('.col-xs-4 input').sendKeys('test-audience').then(function() {
  expect($('.panel-list .panel h3').getText()).toEqual('test-audience');
});
您可以尝试解析
单击
明确承诺:

或者,在单击之前等待元素出现:

var EC = protractor.ExpectedConditions,
    button = $('.panel-list .row .panel-list-header .btn');
browser.wait(EC.presenceOf(button), 5000);
button.click();
// rest of the test

它在哪里失败,如何失败?谢谢。它在$('.panel list.row.panel list header.btn')处大约有50%的时间出错。单击();我已经验证了元素确实存在。因此,错误显示为:失败:使用locator:By.cssSelector(“.panel list.row.panel list header.btn”)找不到元素
var EC = protractor.ExpectedConditions,
    button = $('.panel-list .row .panel-list-header .btn');
browser.wait(EC.presenceOf(button), 5000);
button.click();
// rest of the test