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.
API returns value in Controller but fails to assign to variable
I have a script that checks each row of a table to verify specific attributes are being set properly. I set up a for loop, since each is a child of a known element.
When I enter the following into the Controller I get a number that corresponds to the number of rows in the table:
When I attempt to use this in a script, I get the error, "Cannot read property "childElementCount" from undefined." So I tried assigning the result of the above code to a variable in the Controller as follows:
Why is this happening and how do I get around it? If there is a method that would better allow me to access the attributes of each row element of the table I would be happy to use that.
I am using Sahi OS 4.4 on Windows 7, and am testing in Firefox 34.
When I enter the following into the Controller I get a number that corresponds to the number of rows in the table:
_table("myTable").lastElementChild.childElementCount
The lastElementChild is always the TBODY element.When I attempt to use this in a script, I get the error, "Cannot read property "childElementCount" from undefined." So I tried assigning the result of the above code to a variable in the Controller as follows:
var $rowCount=_table("myTable").lastElementChild.childElementCount
but this returns undefined every time. If I drop "var" I get the correct number in the Controller, but still get the same error in the script.Why is this happening and how do I get around it? If there is a method that would better allow me to access the attributes of each row element of the table I would be happy to use that.
I am using Sahi OS 4.4 on Windows 7, and am testing in Firefox 34.
Best Answers
-
This is really strange....
When dealing with rows, try
_table('mytable').rows.length
-
When assigning DOM related values to proxy variables ( with the $) you have to use the _set () API or _getValue()
var $proxyVariable; _set($proxyVariable, _table("myTable").rows.length); _log($proxyVariable)

Answers
And that returns the following log:
It seems that while it believes it has stored a number, or at least does so initially, it sets the contents of the variable to a string containing the command, not the result... Therefore I get string concatenation with the + operator. Any ideas on how to resolve this?
I've tried to upgrade to OS 5.0 to see if that would resolve this, but I'm getting issues with my Oracle DB interface: I've noticed this has been mentioned in another post with no resolution... Does anybody have any ideas about this one?