Friday, 5 May 2017

Store several elements of page to json object

I need to store several text elements of a page to a json object, however I am not being able to do this in protractor due to asynchronism

Here is one sample of my code, which is inside a loop of element.all():

var json = {};
e[i].element(by.css(".nome_projeto")).getText().then(function(text){
    json.nome = text;
});
e[i].element(by.css(".nome_cliente")).getText().then(function(text){
    json.cliente = text;
});
e[i].element(by.css('.data_fim')).getText().then(function(text){
    json.data = text;
});
console.log(json);
list.push(json);

However when I log my json object is undefined, and I can only access it inside the then



via Rogger Fernandes

No comments:

Post a Comment