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.

API returns value in Controller but fails to assign to variable

bbacabbaca Members
edited May 2015 in Sahi - Open Source
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:
_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

  • edited May 2015 Answer ✓
    This is really strange....

    When dealing with rows, try
    _table('mytable').rows.length
    

  • Answer ✓
    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

  • bbacabbaca Members
    Thanks! That solved the script crashing issue, but there still is an issue with assigning variables... Here is the code I run:
    var $tableLen=_table("myTable").rows.length;
    var $tableLenPlus1 = $tableLen + 1;
    var $tableLenPlus1Parse = parseInt($tableLen) + 1;
    var $tableStart = 2;
    var $tableEnd = -3 + $tableLen;
    _log(typeof($tableLen));
    _log("TableLen=" + $tableLen);
    _log("TableLenPlus1=" + $tableLenPlus1);
    _log("TableLenPlus1Parse=" + $tableLenPlus1);
    _log("TableStart=" + $tableStart);
    _log("TableEnd=" + $tableEnd);
    

    And that returns the following log:
    number at May 19, 2015 10:36:10 AM
    _log(typeof(_table("myTable").rows.length)); at May 19, 2015 10:36:10 AM
    TableLen=6 at May 19, 2015 10:36:10 AM
    _log("TableLen=" + _table("myTable").rows.length); at May 19, 2015 10:36:10 AM
    TableLenPlus1=_table("myTable").rows.length1 at May 19, 2015 10:36:10 AM
    _log("TableLenPlus1=" + "_table(\"myTable\").rows.length1"); at May 19, 2015 10:36:10 AM
    TableLenPlus1Parse=_table("myTable").rows.length1 at May 19, 2015 10:36:10 AM
    _log("TableLenPlus1Parse=" + "_table(\"myTable\").rows.length1"); at May 19, 2015 10:36:10 AM
    TableStart=2 at May 19, 2015 10:36:10 AM
    _log("TableStart=" + 2); at May 19, 2015 10:36:10 AM
    TableEnd=-3_table("myTable").rows.length at May 19, 2015 10:36:10 AM
    _log("TableEnd=" + "-3_table(\"myTable\").rows.length"); at May 19, 2015 10:36:10 AM
    

    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:
    Java constructor for "net.sf.sahi.plugin.DBClient" with arguments "string,string,string,string" not found.
    
    I've noticed this has been mentioned in another post with no resolution... Does anybody have any ideas about this one?
Sign In or Register to comment.