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.

different results with a script run and "Evaluate expression" execution

TSissonCredTSissonCred Members
edited November 2013 in Sahi Pro
Sahi Pro 5.0.9

I'm running the following code inside a function and also within the Controller > Record tab > Evaluate Expression and I'm getting very different results but I can't figure out why.

The code is extracting the client_id from the href attribute of the Profile link:
var $id;
$id = _link("Profile").getAttribute("href");  
_alert($id);
$id = $id.match(/client_id=\d*/).toString();
_alert($id);
$id = $id.substr(10);
_alert($id);

When I run it through the Controller > Record tab > Evaluate Expression field I get the following values for the 3 alerts:
1: /client/client_view.asp?frommycwclient=1&client_id=11345
2: client_id=11345
3: 11345

However, when I the same code either in a script using testrunner or through the Controller > Playback (debug), I get the following values for the alerts:
1. /client/client_view.asp?frommycwclient=1&client_id=11345
2. _sahi._link("Profile").getAttribute("href").match(/client_id=\d*/)
3. k("Profile").getAttribute("href").match(/client_id=\d*/)

As you can see, the call to get the href attribute works fine as both of the initial _alert outputs match. The string matching is where it appears to break. It appears as though it's somehow concatenating the two calls (lines 2 & 4 in the code) as you can see from the 2nd _alert output.

Best Answer

  • Hi TSissonCred,

    Use _set($id , _link("Profile").getAttribute("href")), then it will work, I have tested it :)


    Regards,
    Bhavitha

Answers

  • Hi TSissonCred ,

    Does the above solution worked for you?
    Can the discussion be closed?
  • Sorry Bhavitha, I wasn't notified that you commented. Yes, that code works.

    So what was wrong with my code, and why the different results with executing it in the TestRunner vs the Controller's Evaluate Expression field?
  • Hi ,
    _set API communicates with the browser to evaluate the expression and fetches the result.

    In evaluate expression, the lines that you enter are parsed internally on their own and hence _call,_set etc are not required through Evaluate Expression.

    Regards.
Sign In or Register to comment.