18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
Get text from table cell
Please bare with me as a newbie...
The div tag id in a table cell generates a unique number like so:
<div id="standing_division_wins_458873" class="editable_clean">8</div>
The 458873 is generated for other values in the table.
I can get the text of that cell using this:
_getText(_cell(_table("searchresults_table"), 2, 5));
or similar code for the other rows and columns. But, the text returned is this:
226 new Ajax.InPlaceEditor('standing_division_points_458873', '/reporter/ajax/inline/edit/standing/458873/division_points/', {size:4});
I need the 226 value only, but it varies in length in the different cells I access.
How else can I get only the div tag text, since I can't use the div id because the last number of the id varies?
The div tag id in a table cell generates a unique number like so:
<div id="standing_division_wins_458873" class="editable_clean">8</div>
The 458873 is generated for other values in the table.
I can get the text of that cell using this:
_getText(_cell(_table("searchresults_table"), 2, 5));
or similar code for the other rows and columns. But, the text returned is this:
226 new Ajax.InPlaceEditor('standing_division_points_458873', '/reporter/ajax/inline/edit/standing/458873/division_points/', {size:4});
I need the 226 value only, but it varies in length in the different cells I access.
How else can I get only the div tag text, since I can't use the div id because the last number of the id varies?
Best Answer
-
Hi Simmi,
I have used row name/id and the column idex, from which the value to be accessed, to get a cell value... I was able to get a cell value using the below one line code...
var $dealerAddress = _getText(_row("dealers_tr3").cells[6]);
here, I have saved the cell value (in column 7 of row number 3 in dealers table) to a variable to compare it on next page. I hope this will help...
here "dealers_tr3" is the row identification and [6] is the column index.
Answers
Pl try following code
tsiva suggestion was great and it works in the sahi controller, but running the script give me this error:
_assertEqual(_getText(_table(0).rows[3].cells[1]), "7"); TypeError: _sahi._table(...).rows[3]
Though, using this _assertEqual(_getText(_table(0).rows[3].cells[1]), "7"); in the record mode of the sahi controller's Evaluate Expression gives me True.
I'm using Firefox and here is the snippet of script from the sahi script I am running:
for (var $a=0; $a < $away_scores.length; $a++) {
var $selectCount = 1;
if ($a == $away_scores.length) {
_assertEqual(_getText(_table(0).rows[3].cells[$selectCount]), $row[8]);
} else {
_assertEqual(_getText(_table(0).rows[3].cells[$selectCount]), $away_scores[$a]);
}
$selectCount += 1;
}
So confusing why this is not working!!!
It seems you are using row number instead of row_id. Could you please check with row_id and see whether that works?
I am also not sure whether _table().rows().cells() will works in sahi.
Thank you for the quick reply. OK, so then I add to my script the following to test it out:
_alert(_getText(_cell(_table(0), 3, 1)));
And then get the following error:
_alert(_getText(_cell(_table(0), 3, 1))); Error: The parameter passed to _getText was not found on the browser
But, again when I test it in the Evaluate expression of the controller it works fine. I don't know if this makes a difference, but when I run the script it starts on one page, then opens up a link to another page in a new window. Do you think this would have something to do with the problem? I am so frustrated at this point!!!
UPDATE: It was because of the separate page, so nevermind!!! I figured it out. I was using _click to the link rather than use _navigateTo. Rookie mistake!!!