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.

Number of rows and columns in a webtable

vazidvazid Members
edited November -1 in Sahi - Open Source
Hi,

Is there any way in sahi to find out total number of rows and columns in a table?
I have been using DOM statements by accessing the elements id's, but some how those seem to be not working out for me.

I have a web table, I have to traverse through it to find out the match i require and then perform some action on it.

Appreciate any help on this.

I have been using sahi_20080627 version.

Rgds,
Vazid

Comments

  • Hi,

    This will give you the number of rows in table.
    var Rows = document.getElementById('MyTable').getElementsByTagName('tr');
    var RowCount = Rows.length;
    
    I think the number of columns will be constant and hopefully known beforehand.

    Regards,
    Pankaj.
  • vazidvazid Members
    edited September 2008
    Hey Pankaj,

    Thanks for the quick reply. I have been trying with the syntax you have posted. But sahi, when executed with that particular code stops the execution and the log shows as the <Rows>[variable in above example] undefined.

    So i had to try for the alternative solutions on this.

    Is it possible using any of sahi API's?

    Rgds,
    Vazid.
  • Hi,

    Can you share the piece of code that's giving the error.
    And I hope u had replaced "Mytable" with the name (id) of the table in your web page.

    Regards,
    Pankaj.
  • adminadmin Administrators
    Since that code executes on the browser, make sure you put into a function and use _set to assign it.
    <browser>
    // Since this needs to execute on the browser, use the browser tags around it.
    function getRowLength(){
      var Rows = document.getElementById('MyTable').getElementsByTagName('tr');
      var RowCount = Rows.length;
      return RowCount;
    }
    </browser>
    
    $len = 0;
    _set($len, getRowLength()); // executes getRowLength() on the browser and sets the $len variable on proxy.
    // code which uses $len
    
Sign In or Register to comment.