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.

Some problem with function returning reference to element

tatianatatiana Members
edited November -1 in Sahi - Open Source
Hello,

I'm testing this dummy HTML page:

<html>
<head>
<title>The title</title>
</head>
<body>
<span>Table:</span>
<table>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>Name1</td>
<td><input value="34"/></td>
</tr>
<tr>
<td>Name2</td>
<td><input value="51"/></td>
</tr>
<tr>
<td>Name3</td>
<td><input value="28"/></td>
</tr>
</table>
</body>
</html>

This is my test code:

_checkAge("Name2", 51);
_setAge("Name2", 52);


var $theTable = _table(0);
//var $theTable = _table(0, _under(_span("Table:")));

function _checkAge($name, $expectedAge)
{
var $realAge = _getText(_ageTextBox($name));
_assertEqual($expectedAge, $realAge);
}

function _setAge($name, $age)
{
_setValue(_ageTextBox($name), $age);
}

function _ageTextBox($name)
{
return _textbox(0, _in(_cell($theTable, $name, "Age")));
}

The first function (_checkAge) is working while the second one (_setAge) produces the following error:

_setValue(_ageTextBox("Name2"), 52);
ReferenceError: _ageTextBox is not defined
ReferenceError: _ageTextBox is not defined
at [object Object]. (eval at ([ url].../_s_/spr/concat.js:3034:14)[/url ])
at [object Object].ex ([ url].../_s_/spr/concat.js:3034:9[/url ])
at unknown source

Could you tell me what's the matter? I'm using "_ageTextBox" in the first function too and it's ok.
Another question: if I use

var $theTable = _table(0, _under(_span("Table:")));

instead of

var $theTable = _table(0);

I get the following error message:

_sahi.setServerVar('___lastValue___1317050708828', _getText(_textbox(0, _in(_cell(_table(0, _under(_span("Table:"))), "Name2", "Age")))));
Error: The parameter passed to _getText was not found on the browser
at _checkAge (scripts/implementation.inc:6) at 26-set-2011 17.25.19

Could you tell me please why it isn't working?

Thank you,
Tatiana

OS: Windows XP
Sahi Pro 3.6

Comments

  • First problem resolved, modifying the _setAge function:

    function _setAge($name, $age)
    {
    var $theTextbox = _ageTextBox($name);
    _setValue($theTextbox, $age);
    }

    Still not able to use $theTable variable if defined as relative (under) to a span ( $theTable = _table(0, _under(_span("Table:"))) ).

    Splitting the textbox locator ( _textbox(0, _in(_cell($theTable, $name, "Age"))) ), I see that Sahi manages to locate the table and the cell in the table, but fails to locate the textbox in the cell.

    If I define $theTable = _table(0), the textbox is located correctly.

    Any hint?
    Thank you!
    Tatiana
  • Hi Tatiana,

    Use this:

    _textbox(0, _near(_cell("Name1",_near(_tableHeader("Name")))));

    Check if this works.

    Regards
    Sumitra
  • Hi Sumitra,
    yes, in this way it's working, thank you... but it's slightly different from what I'd like do to.

    I'd like to identify the table under a specific text and then to work upon that table.

    In your solution, what if I had another table with a column "Name"? I'd like to understand if possible what's the matter with my solution, why it isn't working and how I can get it working.

    Thank you very much in advance,
    Tatiana
  • Hi Tatiana,

    Can you try this:

    _cell(_table(0, _under(_span("Table:"))), 1, 1);// Here 1,1 will give you the row index and the column index.

    For the second question, if i have another table with a column "Name" then it would be:

    _textbox(0, _near(_cell("Name1",_near(_tableHeader("Name[1]")))));

    Check if this solves your issue.

    Regards
    Sumitra
  • Hi Sumitra,
    Sumitra wrote:
    Can you try this:

    _cell(_table(0, _under(_span("Table:"))), 1, 1);// Here 1,1 will give you the row index and the column index.

    Sorry, it doesn't work...
    Sumitra wrote:
    For the second question, if i have another table with a column "Name" then it would be:
    _textbox(0, _near(_cell("Name1",_near(_tableHeader("Name[1]")))));

    Yes, you're right, but I was just trying to avoid indexing HTML elements... However, actually your kind of indexing is less technical and more functional than my _table(0).

    Thank you, I think my problem is resolved.

    Regards,
    Tatiana
This discussion has been closed.