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.

Using a string variable

AchimAchim Members
edited November -1 in Sahi - Open Source
Hi,

I am confused about using the following code:

1 var $default;
2
3 $default = _textbox(0).value;
4 _setValue(_textbox(0), $Max);
5 _setValue(_textbox(0), $Min);
6 _setValue(_textbox(0), $default);

My expectation is in the line 6 to receive the value of line 3 ($default). Instead of the expected value I get "_textbox(0).value".

Statement in the Playback window of line 6 is:
_setValue(_textbox(0), _textbox(0).value);

I guess I'm doing something stupid wrong. Can you help?

Regards,

Achim

Comments

  • dpdp Members
    Hi Achim,

    Replace line 3 with _set($default, _textbox(0).value);

    Cheers
    dp
  • narayannarayan Administrators
    Achim,

    Nothing stupid :)

    Accessors of Sahi return an element stub. They are executed only on the browser when you pass it to a browser action API.

    Normal example:
    var $element = _textbox("abc"); 
    // $element is not an element stub
    
    _setValue($element, "123"); 
    // This line sends a string '_setValue(_textbox("abc"), "123")' to the browser 
    // which Sahi's engine executes and returns the result the proxy.
    

    In your case, what you need is to evaluate _textbox(0).value on the browser and get its value.
    You need to use _set in this case.

    Eg.

    1 var $default;
    2
    3 _set($default, _textbox(0).value); // _set fetches the value from the browser and sets it to $default
    4 _setValue(_textbox(0), $Max);
    5 _setValue(_textbox(0), $Min);
    6 _setValue(_textbox(0), $default);


    Hope that helps.

    Regards,
    Narayan
  • AchimAchim Members
    Hi dp, hi Narayan,

    I think I understood my mistake - now everything works fine. Thanks for your help!

    Regards,

    Achim
This discussion has been closed.