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.

The variable can not be parsed in **_setValue** API ????

gyanggyang Members
edited November -1 in Sahi - Open Source
If the script is as below, it returns success info:
<browser>
function getEmailField(){
return _textbox("q");
}
</browser>
_setValue(getEmailField(), "123");
_click(_submit("Google Search"));

But if i modify it to as below, it fail:

<browser>
function getEmailField(){
return _textbox("q");
}
</browser>
var $a=getEmailField();
_setValue($a, "123");
_click(_submit("Google Search"));

I just change **getEmailField()** to be a variable($a).The failure puzzles me.
Please give some explication, thanks.

Comments

  • Hi,

    Try using
    _set($a, getEmailField());
    instead of
    var $a=getEmailField();

    Regards,
    Pankaj.
  • gyanggyang Members
    edited March 2009
    Thanks for your quick reply.

    I change my script as what you suggest, but it still returns error(another error).The error info given in log is **InternalError: too much recursion**

    I check the **Parsed Script **, and found the **$a = _sahi.getServerVar('$a');** there. I don't know why.

    Please give some more tips,thanks.

    Gyang.
  • narayannarayan Administrators
    gyang,

    The Sahi script executes in the proxy. When you do var $a=getEmailField(); you are trying to set something which is on the browser to a variable in the proxy. This cannot happen. In case of _setValue(getEmailField(), "123");, Sahi's _setValue API is designed such that the whole line is sent to the browser and executed there. So that works.

    _set(variableOnProxy, entityOnBrowser) works by serializing the entityOnBrowser into a JSON object and sending it to the proxy to be set to variableOnProxy. You should primarily do this to set individual properties of an object not the whole object. You will not be able to execute any actions on the variableOnProxy because it is a serialized object copy and not the real browser object.

    The recursion happened because html elements have parents and then childNodes which point to the element itself, and during serialization this goes into a loop.

    Hope that makes sense.
    Regards,
    Narayan
  • gyanggyang Members
    to narayan,
    The meaning is clear enough, thanks very much.

    to pankaj,
    Thank you, too.
  • singhsingh Members
    Thanks Narayan,

    It was very helpful !!
Sign In or Register to comment.