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.

_setGlobal/_getGlobal with _getText

rj412rj412 Members
edited November -1 in Sahi - Open Source
Need extra eyes to validate why the following does not work.
It is a syntax error of _setGlobal with _getText?

tried the following with no success:

/*
_setGlobal("Dinner", _getText(_div("Menu For Tonight")));
if ( (_getGlobal("Dinner")) == "Chicken" ) {
orderMore();
} else {
leaveNow();
}
*/

result above always proceeds to leaveNow()

Comments

  • narayannarayan Administrators
    Hi rj412,

    _getGlobal has to be used in a particular way to make it work. In your case, you would need
    _setGlobal("Dinner", _getText(_div("Menu For Tonight"))); 
    if ( _condition(_getGlobal("Dinner") == "Chicken") ) { 
       orderMore();
    } else {
       leaveNow();
    }
    


    _setGlobal and _getGlobal are deprecated. You need not use it in this case. You could do the following:
    // Option 1
    if (_getText(_div("Menu For Tonight")) == "Chicken"){
       orderMore();
    } else {
       leaveNow();
    }
    

    or
    // Option 2
    var $menu;
    _set($menu, _getText(_div("Menu For Tonight")));
    if ($menu == "Chicken"){
       orderMore();
    } else {
       leaveNow();
    }
    

    or

    // Option 3
    if (_condition(_getText(_div("Menu For Tonight")) == "Chicken")){
       orderMore();
    } else {
       leaveNow();
    }
    

    Option 1 is the preferred way.

    Regards,
    Narayan
  • Thanks Narayan.
    But I cant use any of the options #1,#2,#3 given above.
    My global var is only available from the portal.
    So the getGlobal is called from a different window.
Sign In or Register to comment.