Reputation: 79
I have a grid table having many columns and I have to get the text of values of 1st column. The grid table structure is shown below
There is a class for a complete row and then inside this class and each column cell has the same class
<div row-index= 'row1'>
<div col-id= 'datecolumn2' /div>
<div col-id= Name1 /div>
<div col-id= city1 /div>
/div>
<div row-index= 'row2'>
<div col-id= datecolumn2 /div>
<div col-id= Name2 /div>
<div col-id= city2 /div>
/div>
like this, there are around 1000 rows. I have to traverse through each row and get the text of only date column values
Expected: I should get the text of date column class in an array
Upvotes: 0
Views: 145
Reputation: 177
If I understand correctly, you want to iterate through each row and get the value for datecolumn. From your code I see the class name for row and column are shown as they are not same classname. But I assume they are same. It would be more helpfull if you can copy the code from your source. Anyhow with minimal information, I have following code that works to read though the dateColumn from each row and outputs the data in that column.
const datecolumns = element.all(by.css("div.row .datecolumn"));
//If there is another child tag below datecolumn and the text is in that tag then you need to include that class in the above element finder
datecolumns.map(function (eachDateColumn, index) {
eachDateColumn.getText().then(function (dateValue) {
console.log("Date value in column " + index + " is " + dateValue)
})
})
More straight way:
const datecolumns = element.all(by.css("div.row .datecolumn")).getText();
Upvotes: 1
Reputation: 734
It is exactly 1000 rows? do they start at <div class = 'row1'>
and end in <div class = 'row1000'>
?
If that's the case, the element locator itself should be:
element(by.css('.row1 .datecolumn2'));
Then if you're looping through all the rows, just change it like this:
for (i= 1; i < rows.length; i++) {
element(by.css('.row' + i + '.datecolumn2')).getText();
// here you do whatever you need to do with the text
}
Upvotes: 0