How to getText from all rows & columns in an infinite scrolling ng-grid using protractor?

All we need is an easy explanation of the problem, so here it is.

I am trying to write a function which returns the complete grid content in an array. Our ng-grid has infinite scrolling through the rows and also have scrolling through the columns.

I have found an answer for scrolling here Protractor: Scrolling a table and testing for infinite scroll

But I am looking to scroll through the grid fully and get the data, So that I can validate the data when I apply filters to the grid.

Any help on this is highly appreciated, thanks

Sample HTML Code for the rows

<div class="ag-body" style="padding-top: 25px; padding-bottom: 30px;">
  <div class="ag-pinned-left-cols-viewport" style="display: inline; height: 245px;">
    <div class="ag-pinned-left-cols-container" style="width: 480px; height: 1830px; top: 0px;">
      <div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-111 ag-row-index-10" style=" top: 300px; height: 30px;" row-id="111" row="10" v_element_id="19490">
        <div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 0px; width: 35px;" colid="id" v_element_id="19491">
        <div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 35px; width: 245px;" colid="title" v_element_id="19492">June12-AA-3</div>
        <div class="ag-cell ag-cell-no-focus ag-cell-value" style=" left: 280px; width: 200px;" colid="operation_status_enum" v_element_id="19493">INVALID</div>
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-110 ag-row-index-9" style=" top: 270px; height: 30px;" row-id="110" row="9" v_element_id="20136">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-109 ag-row-index-8" style=" top: 240px; height: 30px;" row-id="109" row="8" v_element_id="20153">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-107 ag-row-index-6" style=" top: 180px; height: 30px;" row-id="107" row="6" v_element_id="20170">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-108 ag-row-index-7" style=" top: 210px; height: 30px;" row-id="108" row="7" v_element_id="20187">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-105 ag-row-index-4" style=" top: 120px; height: 30px;" row-id="105" row="4" v_element_id="20204">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-106 ag-row-index-5" style=" top: 150px; height: 30px;" row-id="106" row="5" v_element_id="20221">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-104 ag-row-index-3" style=" top: 90px; height: 30px;" row-id="104" row="3" v_element_id="20238">
<div class="ag-row ag-row-no-focus ag-row-odd ag-row-level-0 ag-row-id-102 ag-row-index-1" style=" top: 30px; height: 30px;" row-id="102" row="1" v_element_id="20255">
<div class="ag-row ag-row-no-focus ag-row-even ag-row-level-0 ag-row-id-103 ag-row-index-2" style=" top: 60px; height: 30px;" row-id="102" row="1" v_element_id="20258">

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

You need to find the last row from the dom and use scrollintoview javascript function. please find the example below.

var last_row=element.all(by.css(".ag-row")).last() //this will give you the last row from the grid

This will scroll the entire grid.Now you can get all the text from row by

element.all(by.css(".ag-row")).getText().then(function(RowValueArray) { 
         //do whatever you want to do with the values.

Hope it helps you!

Method 2

I am able to scroll through the grid and get the data from all rows in the following way. I got the scrollDown code from Protractor: Scrolling a table and testing for infinite scroll (thanks @alecxe)

There is little hard coding in the for loop. I should find out a way to know how many times I should scrollDown the table. Also the final result have some duplicates will need to clean it up.

    scrollDown() {
    return browser.executeScript("return arguments[0].offsetTop;", this.lastRow.getWebElement()).then((offset) => {
      browser.executeScript("arguments[0].scrollTop = arguments[1];", element(by.className("ag-body-viewport")).getWebElement(), offset);

  getRows() {
    return this.pinnedRows.getText();

  getTotalRows() {
    const defer = Promise.defer();
    let allRows = [];

    for (let i = 0; i < 3; i++) {
      this.getRows().then((rows) => {
        allRows = allRows.concat(rows);
        if (i === 2) {
    return defer.promise;

  waitToLoad() {

In the spec:

  getTotalRows().then((data) => {`TOTAL ROWS: ${data}`);`TOTAL NUMBER OF ROWS : ${data.length}`);

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply