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.

Getting Text Then Storing to Substring

spchinspchin Members
edited July 2011 in Sahi - Open Source
I am trying to get text from an element on a page then store parts of that text to other variables. The script looks like this right now:

var $one = _getText(_select("blank"));
var $two;
_set($two, $one.substring(8,15));
var $three;
_set($three, $one.substring(3,6));

I stepped through the code and the first line runs fine, but the second line I get an error. This code worked in a previous version of Sahi, but not V3.5. Can anyone suggest a different syntax please?

Comments

  • TheeranTheeran Members
    Hai spchin,

    I tried with this script and it is working fine.
    var $one=_getText(_select("blank"));
    var $two=$one.substring(8,15);
    var $three=$one.substring(3,6);
    

    And may i know,what $blank is because it looks like it hasn't been initialized anywhere. Which version of sahi you are using?
    Also, what error are you getting and what browser are you using?


    Regards
    Theeran.
  • spchinspchin Members
    Thanks for the help Theeran. That was a typo on my part, $blank should actually be $one. I tried the code you supplied but I am getting an error saying that I am missing a ; before var $two=$one.substring(8,15);

    I am using IE 8 and Sahi V3.5
  • spchinspchin Members
    Edited original post for clarity
  • guys i have similar issue

    I am trying with the above code but it dint work

    Here is my code:
    var $one=_getText(_div("5 FOLLOWING"));//Here i have entered the name of the div.
    var $two=$one.substring(1,1);
    _click(_div($two+FOLLOWING));

    Here i have to get the text from the div "5 following" as everytime the count keep incrementing i need to fetch the number from the text.

    Can idea on this?
  • Hi chethshetty,
    I think replacing the line:
    _click(_div($two+FOLLOWING));
    
    with
    _click(_div($two+" FOLLOWING"));
    
    should make it work for you.

    Regards.
Sign In or Register to comment.