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.

Can I get the javascript alert message in a variable?

lawrencelawrence Members
edited November -1 in Sahi - Open Source
I am using Sahi V3.5

Comments

  • I have a form which has 2 mandatory fields. When the Save button is clicked, it gives the following alert message:
    - 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?
  • narayannarayan Administrators
    Hi,

    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
  • Thanks narayan,
    \r\n works for me.
This discussion has been closed.