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.

Storing a changing value in a variable

FortexFortex Members
edited November -1 in Sahi - Open Source
The first time I click a certain button on a page, this message appears: User's password reset to sahi
If I click the same button again and again, the same message stays there BUT only the last word "sahi" changes

I would like to store "sahi", which changes each time I click the button, in a variable
I would also like to paste the value in the variable in a text field.


Can you please help me. I am not a programmer but I love sahi so much that I am trying to make a defacto testing tool in our company.

Thank you very much,

Fortex

Comments

  • narayannarayan Administrators
    Fortex, glad you like Sahi.
    For your problem, first we need to find out whether "User's password reset to sahi" is inside a div or span. What do you see as the accessor if you CTRL-mouseover that line? You could email the html content of the page (view source) to narayan@sahi.co.in if you are not sure.
  • It is inside a div. Here is the code:

    <div id='messages'><ul class='messages'>
    <li class='info' title='User.info.passwordReset'>User's password reset to sahi</li>
    </ul></div>
    From sahi controller:

    Accessor: _byId("messages")
    Alternative:top.frames[0].document.getElementById('messages')
    Value: User's password reset to sahi

    I hope this helps,
    Thank you again for your help,
  • narayannarayan Administrators
    <browser>
    function fetchPassword(){
        var message = _getText(_byId("messages"));
        var prefix = "User's password reset to ";
        var password = "";
        var ix = message.indexOf(prefix);
        if (ix > -1){
            password = message.substring(ix + prefix.length);
            password = _sahi.trim(password);
        }
        return password;
    }
    </browser>
    
    
    
    $password = "";
    _set($password, fetchPassword());
    //...
    _setValue(_password("your_password_box"), $password);
    
  • FortexFortex Members
    edited November 2008
    Thank you very much narayan. I really do appreciate it. I have one more question:
    Does this look OK to you?

    _click(_link("USERTWOU01"));
    _wait(500);
    _click(_button("Reset Password"));
    _wait(300);

    <browser>
    function fetchPassword(){
    var message = _getText(_byId("messages"));
    var prefix = "User's password reset to ";
    var password = "";
    var ix = message.indexOf(prefix);
    if (ix > -1){
    password = message.substring(ix + prefix.length);
    password = _sahi.trim(password);
    }
    return password;
    }
    </browser>

    $password = "";
    _set($password, fetchPassword());
    _click(_button("Save"));
    _wait(400);
    _click(_link("Sign Out"));
    _wait(400);
    _setValue(_textbox("username"), "USERTWOU01");
    _setValue(_password("password"), $password);
    _click(_submit("Login"));
    ====================================

    BUT when I run it, the controller doesn't go beyond: _click(_link("Sign Out"));

    Thank you again very much,

    ~Fortex
Sign In or Register to comment.