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.

_prompt and _confirm not working

PachatPachat Members
edited November -1 in Sahi - Open Source
_prompt(message) and _confirm(message) described http://sahi.co.in/w/browser-action-apis
are not event parsed.

So we get a --FAILURE--

So I tried to add them to scheduler_functions.txt.
But then, it was impossible to navigateTo.

Is there a patch to get _prompt(message) and _confirm(message) working properly ?

Comments

  • narayannarayan Administrators
    Hi Pachat,

    You are right, _prompt and _confirm are not exposed as APIs by Sahi right now.

    Please have a look at this http://sahi.co.in/forums/viewtopic.php?id=2038 to see how _prompt can be used.

    _confirm is similar.

    Regards,
    Narayan
  • narayan,

    It works !

    I gave a little enhancement, allowing to custumize the message
    <browser>
    function promptForUserInput(message){
        _sahi_temp_promptValue = _sahi._prompt(message);
    }
    </browser>
    
    function getUserInput($message){
        var $value = null;
        _call(promptForUserInput($message));
        _set($value, _sahi_temp_promptValue);
        return $value;
    }
    
    
    // Get the user input in your script
    var $userInput = getUserInput('Enter a name');
    _alert($userInput);
    

    Thank you for your support
  • narayan wrote:
    _confirm is similar.
    Regards,
    Narayan

    In fact, for some reasons, it looks like not to be quite similar.
    The following code does not work
    <browser>
    function confirmForUserInput(message){
        _sahi_temp_confirmValue = _sahi._confirm(message);
    }
    </browser>
    
    function confirm($message){
        var $value = null;
        _call(confirmForUserInput($message));
       //Firebug says :  _sahi_temp_confirmValue is not defined
        _set($value, _sahi_temp_confirmValue);
    
        return $value;
    }
    
    
    // Get the user input in your script
    var $userInput = confirm('Are you sure ?');
    _alert($userInput);
    
    What am I doing wrong ?
  • narayannarayan Administrators
    Hi Pachat,

    _confirm function was not defined on Sahi. Use the code below:
    <browser>
    function confirmForUserInput(message){
        _sahi_temp_confirmValue = _sahi._confirm(message);
    }
    Sahi.prototype._confirm = function (s) {
        return this.callFunction(this.real_confirm, window, s);
    };
    </browser>
    
    function getConfirmResult($message){
        var $value = null;
        _call(confirmForUserInput($message));
       //Firebug says :  _sahi_temp_confirmValue is not defined
        _set($value, _sahi_temp_confirmValue);
    
        return $value;
    }
    
    
    // Get the user input in your script
    var $userInput = getConfirmResult('Are you sure ?');
    _alert($userInput);
    

    Note that I am using getConfirmResult instead of confirm. If not, any javascript code calling confirm() will invoke this function, instead of Sahi's mock confirm function.

    Regards,
    Narayan
  • Great! It works fine.

    Thanks
This discussion has been closed.