Reputation: 674
I am trying to login on my website using an array of accounts
in CasperJS.
casper.start()
.then(function() {
accounts.forEach(function(account) {
casper.thenOpen('http://mywebsite/login', function() {
casper.fill('form.form-type1', account, true);
casper.waitForSelector(".widgetContainer-widget-title", function() {
var elemsCount= this.evaluate(function() {
var elem= $('.widget-personal');
return elem.length;
});
this.echo(surveysCount + ' elemsCount ' + account['username'] + '\n');
});
});
});
});
casper.run(function() {
this.echo('----------- Donenzo, enjoy! ------------\n');
this.exit();
});
Now, the code is working fine but the number returned is always 0, because when widgetContainer-widget-title
is fully rendered, widget-personal
is not yet ready, hence it cannot find any element at that point in time so returns 0 and this is because my website is an Angular app and regrettably has a delay when communicating to the DB. Any idea of how to wait until a page is completely rendered to apply a test?
Upvotes: 1
Views: 864
Reputation: 674
[ANSWER]
I worked around it by waiting on the .widget-personal
element itself, rather than its parent. It is an ugly workaround but it works, and then I am catching the errors thrown by the timeout as described per: casper.waitForSelector, timeout and error handling
Upvotes: 1