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.
Simple if/else decision with sahi
In my script I have a heading that I need to assert is on the page. If the heading matches "sahi for mlive.com" then I want to click on the link with the heading called "sahi for mlive.com". Else I want to click on a link with the heading "Sahi Index Page for mlive.com".
I started with this script:
var $link;
if( _assertExists(_heading1("sahi for mlive.com"))){
_click(_heading1("sahi for mlive.com"));
_set($link, _link(1).getAttribute("href"));
_debug($link);
_navigateTo($link);
}
else{
_click(_heading1("Sahi Index Page for mlive.com"));
_set($link, _link(1).getAttribute("href"));
_debug($link);
_navigateTo($link);
}
However, the script above fails. The if/else condition is ignored and automatically the link with heading "sahi for mlive.com" is clicked, even if the heading does not exist.
Alternatively, I tried this script below:
_assertNotExists(_heading1("sahi for mlive.com"),_click(_heading1("Sahi Index Page for mlive.com")));
However it does not work well because it does not allow me to manage the condition of the heading if 'sahi for mlive.com' exist.
Please let me know another approach to resolving this issue.
I started with this script:
var $link;
if( _assertExists(_heading1("sahi for mlive.com"))){
_click(_heading1("sahi for mlive.com"));
_set($link, _link(1).getAttribute("href"));
_debug($link);
_navigateTo($link);
}
else{
_click(_heading1("Sahi Index Page for mlive.com"));
_set($link, _link(1).getAttribute("href"));
_debug($link);
_navigateTo($link);
}
However, the script above fails. The if/else condition is ignored and automatically the link with heading "sahi for mlive.com" is clicked, even if the heading does not exist.
Alternatively, I tried this script below:
_assertNotExists(_heading1("sahi for mlive.com"),_click(_heading1("Sahi Index Page for mlive.com")));
However it does not work well because it does not allow me to manage the condition of the heading if 'sahi for mlive.com' exist.
Please let me know another approach to resolving this issue.
Answers
var $text=_getText(_heading1(1));
if($text=="Sahi Index Page for mlive.com"){
_click(_heading1("Sahi Index Page for mlive.com"));
}else{
_click(_heading1("sahi for mlive.com"));
}
//navigate to preview page link
//_navigateTo("http://www-dev.mlive.com/preview/sahi/index.html?asdf", true);
var $link;
//_set($link, _getValue(_heading1(1)));
_set($link, _link(1).getAttribute("href"));
_debug($link);
_navigateTo($link);