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.

Problem with _set()

pankaj.nithpankaj.nith Members
edited November -1 in Sahi - Open Source
Hi,

Here is my code snippet:
var $quest1 = /\[\d*\] Text Statement/;
var $y1;
_set($y1, _spandiv($quest1).innerHTML);
var $val = $y1.substring(1, 5);
_alert($val);
Now my problem is that although the value of $y1 is getting set properly and alert shows the proper value that i need. But the results show script failed with error as: "TypeError: $y1 has no properties".

Anybody having a solution or any idea plz help me.

Thanks and Regards,
Pankaj.

Comments

  • Hi,

    Only thing I could figure out is that its appearing due to the jscript function substring() that i m using.
    Any other way to get a substring from the text? I need to get the numeric part from the text. I hope regular expression can help. Please suggest.

    Regards,
    Pankaj.
  • Solved it :)
    will b back if I get stuck again..:)

    Thanks.
    Pankaj.
  • Could you share the solution with the rest of us?
  • Hi,

    Sure i will. Thats the purpose of this community after all..:)
    I tried this:
    var $quest = /\[\d*\] My Text/;
    var $key;
    _set($key, _getText(_spandiv($quest)).match(/\d\d\d\d/));
    
    I needed the four digit number here.
    Instead of assigning the required value to a variable later on, its always better to assign it directly in the _set() statement itself.

    Regards,
    Pankaj.
  • So was the problem coming from _set() ?
    Because I've got a big problem (similar as yours) with _set() function...
    If I use it, I have an "element has no properties" failure ...!
    The code is in my "Selected Boxes" topic just in case :)
  • StringyLowStringyLow Members
    edited June 2008
    Ok, I'm stumped, too...

    I swear to God this worked yesterday:

    _set($current_budget, _textbox("campaignbudget").value);

    Today I'm seeing this error:

    handleSet('\$current_budget' + 10, _textbox("campaignbudget").value);
  • Hi lepierrot,

    Try using the last loop in your code in a function as you did for the other part. The issue is same: page dependent variables used in for loop.

    function abc(){
    for( var $i=0; $i < $countries_gsm_d.length; $i++){
    $arr[$i] = _select("dev_country").options[$i].text;
    }
    }

    Regards,
    Pankaj.
  • Hi StringyLow,

    Please write your code snippet if possible. we can have a better understanding then and think it over :)

    Regards,
    Pankaj.
  • Hi Pankaj,

    I don't understand chat you said because my code works fine..!

    function abc($countries_gsm_d, $arr){
    for( var $i=0; $i < $countries_gsm_d.length; $i++){
    $arr[$i] = _select("dev_country").options[$i].text;
    }
    }
    is not a problem ...
    But it's not useful because after the first function, I already have an array that contains the list of my options (countries) ... so it's useless!
  • I think the _set problem I have has to do with the length of the script I'm using.

    The _set I'm having trouble with is at the top of the script. If I copy that portion and run it as a separate script, it works fine.

    If I incorporate it into a longer script of 150 lines or so, it fails.

    It's seems like the variable is undefined...

    ... and I just looked at the log and there is much more information in there:

    I'm going to do some more investigating.
  • Hi,

    Got any further?
  • I got it figured out.

    I was mixing variables with "$" and no $.
  • narayannarayan Administrators
    edited July 2008
    To explain why the code in the first post failed:

    This code
    var $quest1 = /\[\d*\] Text Statement/;
    var $y1;
    _set($y1, _spandiv($quest1).innerHTML);
    var $val = $y1.substring(1, 5);
    _alert($val);
    
    after parsing, will become:
    var $quest1 = /\[\d*\] Text Statement/;
    var $y1;
    _schedule("_set($y1, _spandiv($quest1).innerHTML);")
    var $val = $y1.substring(1, 5);
    _schedule("_alert($val);");
    
    So the sequence of execution has become:
    var $quest1 = /\[\d*\] Text Statement/;
    var $y1;
    var $val = $y1.substring(1, 5);
    // and later
    _schedule("_set($y1, _spandiv($quest1).innerHTML);")
    _schedule("_alert($val);");
    
    So the substring fails, since $y1 has not been initialized!
    The correct way would be:
    var $quest1 = /\[\d*\] Text Statement/;
    _alert(_spandiv($quest1).innerHTML.substring(1, 5));
    
    or
    var $quest1 = /\[\d*\] Text Statement/;
    var $y1, $val;
    _set($y1, _spandiv($quest1).innerHTML);
    _set($val, $y1.substring(1, 5));
    _alert($val);
    
    I would recommend the former solution.
  • Great! This will really help in understanding how sahi internally works that will again help to code better.
    This piece of information really describes many things.:)

    Thanks :)
    Pankaj.
  • Schedule functions in Sahi are very weird ...!
  • I suppose the upshot of this tutorial is that scripts should make use of the DOM as much as possible.

    http://www.w3schools.com/htmldom/dom_using.asp
Sign In or Register to comment.