18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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.
My iF/else works on Evaluate Expression but it doesn't work in my script
PremiumReflexes
Members
I have an image on my Web Application.
_f("myApp").s_image("myImg")
When I click on this image, his property "enabled=true" becomes "enabled=false".
I need to test that.
on the SAHI controller when I test this code :
_f("myApp").s_image("myImg").get("enabled")=="true"
SAHI give me true when enabled=true and false when enabled=false.
So far so good.
In my test.sah, I test this value in this manner :
if(_f("myApp").s_image("myImg").get("enabled")=="true"){
_click(_f("myApp").s_image("myImg"));
_alert('Click');
}else{
_alert('Test 1 failed');
}
if(_f("myApp").s_image("myImg").get("enabled")=="true"){
_click(_f("myApp").s_image("myImg"));
_alert('Click !');
}else{
_alert('Test 2 failed');
}
I have also test all the if/else in my sahi Evaluate Expression and it works...
I don't understand why it works on the panel Evaluate Expression of SAHI Controller and not in my script.
_f("myApp").s_image("myImg")
When I click on this image, his property "enabled=true" becomes "enabled=false".
I need to test that.
on the SAHI controller when I test this code :
_f("myApp").s_image("myImg").get("enabled")=="true"
SAHI give me true when enabled=true and false when enabled=false.
So far so good.
In my test.sah, I test this value in this manner :
if(_f("myApp").s_image("myImg").get("enabled")=="true"){
_click(_f("myApp").s_image("myImg"));
_alert('Click');
}else{
_alert('Test 1 failed');
}
if(_f("myApp").s_image("myImg").get("enabled")=="true"){
_click(_f("myApp").s_image("myImg"));
_alert('Click !');
}else{
_alert('Test 2 failed');
}
I have also test all the if/else in my sahi Evaluate Expression and it works...
I don't understand why it works on the panel Evaluate Expression of SAHI Controller and not in my script.
Best Answers
-
You can use _set($result,_f("myApp").s_image("myImg").get("enabled"))
if($result==true)
{
} -
That's because there are 2 JavaScript scopes. While SahiScript resides somewhat in the SahiProxy, JavaScript runs in the browser and accesses the DOM elements. The SahiController runs your 'evaluate expression' in the browser, suite playback does not.
Sometimes you need to tell the Proxy where to run the expression. One Example is set(). With set, we access the DOM, read a value and write it into a proxy variable.
When using 'if conditions' in SahiScript which depend on a DOM element, you can alternatively use 'if(_condition())'. see http://sahi.co.in/w/if-condition and http://sahi.co.in/w/sahi-script-and-javascript
This discussion has been closed.

Answers
But Could you tell me what this function doing ? (_set())
Because It's apparently different that :
var $result = _f("myApp").s_image("myImg").get("enabled");