18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

Data Extraction

PanginoonPanginoon Members
edited November -1 in Sahi - Open Source
I know Sahi's main focus is Automation and Testing, however, I have come across a need to extract table data.

I figured out how to get the number of rows:

<browser>
function getRows(){
var Rows = _table($tableNo).rows.length;
return Rows;
}
</browser>

_set($rows, getRows());

I have devised a way to get each cell's text (I'm sure it could be improved):
function getTable($tableNo){
for (var $i=0; $i<$rows; $i++){ //for each row
for (var $p=0; $p<$cols; $p++){ //for each cell
_set($cellText, _getText(_cell(_table($tableNo), $i, $p)));
_set($row[$i], $row[$i] + $cellText + ',');
}
}
}

In my table on column is for color swab images (orange, red, blue, etc) the title of the image is the color. Each row's color swab may be different and the _image[#] isn't always accurate. Is there a way to find the image in a row?

How do I go about improving my getTable function and how

Comments

  • narayannarayan Administrators
    Ponginoon,

    Have a look at this forum post to see new features for accessing tables http://sahi.co.in/forums/viewtopic.php?id=816.

    You could do this to get all data in a table:
    <browser>
    function getTableData(){
      var tableData = new Array();
      var table = _table(0);
      for (var i=0; i< table.rows.length; i++){
          var row = table.rows[i];
          tableData[i] = new Array();
          for (var j=0; j< row.cells.length; j++){
              tableData[i][j] = _getText(row.cells[j]);
          }
      }
      return tableData;
    }
    </browser>
    _set($tableData, getTableData());
    
    for (var $i=0; $i<$tableData.length; $i++){
        for (var $j=0; $j<$tableData[$i].length; $j++){
            _highlight(_cell($tableData[$i][$j]));
        }
    }
    
    First, collect the cell text into a 2D array on the browser, pass it back to the proxy and assign to $tableData using _set. And then work on $tableData.
Sign In or Register to comment.