Tom Nijs
Tom Nijs

Reputation: 3950

Gathering a value from a column from each row from a table into an array in protractor

Writing e2e tests for an Angular App, but I don't seem to be able to get my head around async programming and promises. I'm attempting to get the value from each row, from the first column and add that to an array to eventually sort it from high to low to have the highest value. I'm having some trouble resolving the promise of my rows.each, the errormsg is: 'TypeError: undefined is not a function'

//This function will fetch the highest ID from the columns
this.getHighestScheduleId = (function(){
    //Array to collect the ID's in
    var idArray = [];
    //Collects all the rows in our table
    var rows = $$('#schedulesData');
    //Goes through each row
    rows.each(function(row){
        //Collect all the row's elements in rowElems
        var rowElems = row.$$('td');
        console.log(rowElems[0].getText());
    });
});

Upvotes: 1

Views: 690

Answers (1)

alecxe
alecxe

Reputation: 473823

map() would fit nicely here:

rows.each(function(row) {
    var rowElems = row.all('td').map(function (td) {
        return td.getText();
    });

    // resolve the promise to see the output on the console
    rowElems.then(function (values) {
        console.log(values);
    });
});

Upvotes: 1

Related Questions