Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

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

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.