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.

URGENT !!!!! Partial value save in a variable

1701198117011981 Members
edited November -1 in Sahi - Open Source
can we save the partial value in a variable

e.g. the text is

Submitted by Super User on 03/05/2009

Now, i just want to save the value "03/05/2009" in a variable.

Comments

  • narayannarayan Administrators
    $s = "Submitted by Super User on 03/05/2009"
    $s = $s.replace(/Submitted by Super User on /, "");
    
    should work I hope.
  • Hi narayan

    In this text, "Submitted by Super User on 03/05/2009"

    this date is dynamic and "Super User" is the first name and last name of user and is also dynamic...

    I need to store the date only in a variable... irrespective of this text ...
  • narayannarayan Administrators
    $s = "Submitted by Super User on 03/05/2009"
    $s = $s.replace(/Submitted by .* on /, "");
    
    or
    $s = "Submitted by Super User on 03/05/2009"
    $s = $s.replace(/.*[ ]/, ""); // match anything upto and including last space.
    
  • thanks narayan,

    this solution seems to be working...
    but there is a little problem

    date To field is a date picker...once i selected the date using date picker...i am unable to store this date in a variable....and this is a shop stopper to this entire solution....

    Please provide solution for this...

    Script i am using :

    var $date;
    _set($date, _getText(_textbox("id")));
  • Narayan, thanks for rthe qyuick response...but i am still been stuck....

    Actually, in the text:

    "Submitted by Bradd Nathan on 05/03/2009"

    Here the date is variable...(which i need to store in a variable)
    the user name "Bradd Nathan" is also variable ...but the solution u gave is ok to me...

    Code:
    $s = "Submitted by Super User on 03/05/2009"
    $s = $s.replace(/.*[ ]/, ""); //

    Here, in the solution u provide, the date has become hard coded (03/05/2009)...now everytime, in the variable $s, it will store the date as "03/05/2009"...while in this variable i need to store the varible date....

    Please provide ur solution... as this has stopped my progress...
  • Hi,

    if its always the current date than you can try this:

    var $now = new Date();
    var $monthday = $now.getDate();
    var $month = parseInt($now.getMonth()) + 1;
    var $year = $now.getFullYear();
    var $currentDate = $month + "/" + $monthday + "/" + $year;

    $s = "Submitted by Super User on " + $currentDate;
    $s = $s.replace(/.*[ ]/, "");

    Regards,
    Pankaj.
  • pankaj..thnx for the reply...but this is not always the curent date this date varies from back date to current date...
  • from where do you get this string? i mean is it displayed on your web page?
    if yes, than you can store it in a variable first and then use it.
  • narayannarayan Administrators
    17011981, (I wish you got a proper name like the rest of us! :) )

    $s = "Submitted by Super User on 03/05/2009"

    was an example.

    You would mostly have to do this
    $s = "";
    _set($s, _getText(_spandiv("message"))); // Again an example. replace _spandiv("message") with the element that has that message.
    $s = $s.replace(/.*[ ]/, "");
    
    Btw, I did not understand your problem regarding
    var $date;
    _set($date, _getText(_textbox("id")));
    
    Did you get a solution for it?

    Regards,
    Narayan
  • Hi,

    if it is a textbox with some prefilled data (date), i think
    var $date;
    _set($date, _getText(_textbox("id").value));
    should work.

    Regards,
    Pankaj.
  • Oops! it should be
    var $date;
    _set($date, _textbox("id").value);
Sign In or Register to comment.