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.
sahi doesn't execute an if condition
hello i'm new in sahi and i'm trying to write a script with an if condition inside well the problem is when i playback my my script sahi doesn't execute the if and skip it to to the other step after i tried a lot of things but it doesn't work . here is my script:
function($code,$RS,$TRS,$CP,$Ville)
{
_click(_cell("Cr\351er"));
_setValue(_textbox("codeFournisseur"), $code);
_setValue(_textbox("raisonSociale"), $RS);
_setSelected(_select("typeRS"), $TRS);
_setValue(_textbox("codePostal"), $CP);
_setValue(_textbox("ville"), $Ville);
_click(_cell("Cr\351er"));
var $alert = "Ce fournisseur existe d\351j\340.Il ne peut pas \352tre cr\351\351 de nouveau";
_log($alert); // i tried this exemple from a suggestion i found in the forum
if($alert != "Ce fournisseur existe d\351j\340.Il ne peut pas \352tre cr\351\351 de nouveau")
{ _click(_cell("Annuler"));}
else {_click(_cell("Valider"));
_click(_cell("Rechercher"));
}
and here is the result that i get after ^playing back my script :
_click(_cell("Cr\351er"));
_setValue(_textbox("codeFournisseur"), "0008");
_setValue(_textbox("raisonSociale"), "TEST CREER FOURNISSEUR 2");
_setSelected(_select("typeRS"), "DEPOT");
_setValue(_textbox("codePostal"), "42000");
_setValue(_textbox("ville"), "ST ETIENNE");
_click(_cell("Cr\351er"));
_log("Ce fournisseur existe déjà.Il ne peut pas être créé de nouveau"); // check if the message comes up correctly
_click(_cell("Rechercher"));
help me please thank you
function($code,$RS,$TRS,$CP,$Ville)
{
_click(_cell("Cr\351er"));
_setValue(_textbox("codeFournisseur"), $code);
_setValue(_textbox("raisonSociale"), $RS);
_setSelected(_select("typeRS"), $TRS);
_setValue(_textbox("codePostal"), $CP);
_setValue(_textbox("ville"), $Ville);
_click(_cell("Cr\351er"));
var $alert = "Ce fournisseur existe d\351j\340.Il ne peut pas \352tre cr\351\351 de nouveau";
_log($alert); // i tried this exemple from a suggestion i found in the forum
if($alert != "Ce fournisseur existe d\351j\340.Il ne peut pas \352tre cr\351\351 de nouveau")
{ _click(_cell("Annuler"));}
else {_click(_cell("Valider"));
_click(_cell("Rechercher"));
}
and here is the result that i get after ^playing back my script :
_click(_cell("Cr\351er"));
_setValue(_textbox("codeFournisseur"), "0008");
_setValue(_textbox("raisonSociale"), "TEST CREER FOURNISSEUR 2");
_setSelected(_select("typeRS"), "DEPOT");
_setValue(_textbox("codePostal"), "42000");
_setValue(_textbox("ville"), "ST ETIENNE");
_click(_cell("Cr\351er"));
_log("Ce fournisseur existe déjà.Il ne peut pas être créé de nouveau"); // check if the message comes up correctly
_click(_cell("Rechercher"));
help me please thank you
Best Answer
-
This is just syntax related. Make sure to write you conditions as
if ($condition) { _click($link); } else { _click($link) }
Sahi ignores statements likeif ($condition) { _click($link); //ignored } else { _click($link) //ignored }
adapt your coding and you'll be fine
regards
Wormi

Answers