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.
Can I get the javascript alert message in a variable?
I am using Sahi V3.5
This discussion has been closed.
Comments
- Select event type
- Select event category
I recorded the script and below is the edited script:
xyxyxyxyxy
xyxyxyxyxy
_clearLastAlert();
_click(_submit("Save"));
if(_lastAlert() == "- Select event type\n- Select event category")
{
_alert("pass");
}
else
{
_alert("Fail");
}
During playback, it always shows "Fail". What I have to correct here?
It could be \r\n instead of \n, or there may be more spaces involved. You could try
var $alert = _lastAlert();
_log($alert); // check if the message comes up correctly
if($alert.replace(/\s+/g, ' ') == "- Select event type - Select event category")
{
_alert("pass");
}
else
{
_alert("Fail");
}
It replaces all multiple whitespace chars with a single space
Regards,
Narayan
\r\n works for me.