1

I have an angular grid with 3 rows. All three rows come under same class A. but ever row has it xpath webelement B (//div). How to iterate through each cell of 1st two rows and get the values in an array? Please help me in this.

There is no repeater. When I tried using getting text of each cell of 1st row using div xpath webelement B then it is giving me result like this:

cell1
cell2
cell3

But I need result in this format

['cell1', 'cell2', 'cell3']

and when I get text of class A then it is giving me in proper format but all the cells of 3 rows are coming. like ['cell1', 'cell2', 'cell3', 'cell6'........]

I have written like this:

var expectedCells = element.all(by.css('.A); - using class A
expectedCells.each((eachCell) => {
    eachCell.getText().then((cellText) => {
        expect(expectedCells).toEqual([['cell1', 'cell2', 'cell3'])
    });
}) 

Expected: ['cell1', 'cell2', 'cell3']

Actual: giving me last cell text only

Bill P
  • 3,622
  • 10
  • 20
  • 32

2 Answers2

1

You can do it with less lines, using map:

let elements = element.all(by.css('.A'));

elements.map(el => el && el.getText()).then( textarray => {
    expect(textarray).toEqual(['cell1', 'cell2', 'cell3']);
});
Infern0
  • 2,565
  • 1
  • 8
  • 21
0

Try the below one

var expectedArray[] = ['cell1', 'cell2', 'cell3'];
var expectedCells = element.all(by.css('.A); - using class A
var textArray[];
for(i=0;i<expectedCells.count();i++){
    expectedCells.get(i).getText().then((cellText) => {
    textArray[i]= cellText;
 });
}
expect(textArray).toBe(expectedArray);

Hope the above code helps you.

Madhan Raj
  • 1,404
  • 1
  • 7
  • 13