18 January 2026:
Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.
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 an issue with the getCellText method here..
Hi, Just playing around with Sahi to check the suitability of screen testing a financial portal. The testing mechanism itself looks very good and was quick to set up. I tried to write a simple script to validate whether 2 fields from a screen add up to a third . ie: a+b=z
I used the _getCellText method to pull out data from the screen in this format - "($294,098)" There is a _stringFilter() in the imported one.sah which strips the chars and retrieves the value as -294098 (Brackets indicate a negetive value).
It'd be great if someone could help me and let me know where I am goofing up. I seem to be getting issues with the _set method.
Here is the code:
_include("one.sah");
var $a=0;
var $b=0;
var $z=0;
var $aa=0;
var $bb=0;
var $zz=0;
// This function is working fine..
function _navigateToAlphaAndLogin($username,$password,$customer,$opportunity)
{
_setValue(_textbox("username"),$username);
_click(_submit("Login"));
_click(_link($customer));
_click(_link($opportunity));
_click(_link("Formula Rated Version"));
}
_navigateToAlphaAndLogin("sree","sree","De Paul University","JMeter-Sngl-Med-Assn-09/10/08 13:35:41");
//MARK: value a
// This assert works fine.There is a value coming in.
_assertEqual("($294,098)", _getText(_cell(_table(10), 11, 1)));
// Something missing here........
_set($aa, _stringFilter(_getText(_cell(_table(10), 11, 1))));
alert($aa);
$a= _stringFilter($aa);
//MARK: value b
_set($bb,_getCellText(_cell(_table(10), 12, 1)));
$b= _stringFilter($bb);
//MARK: value z
_set($zz, _getCellText(_cell(_table(10), 13, 1)));
$z= _stringFilter($zz);
_alert($a+$b);
//validation
_assertEqual($z, $a+$b);
//one.sah
function _stringFilter (s) {
//s = replaceChars(s);
if(s.charAt(0)=='('){
s = s.replace("(","-");
}
filteredValues = "$%)," ; // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
//input.value = s;
if (filteredValues.indexOf(c) == -1)
returnString += c;
}
var $num = new Number(returnString);
alert($num);
return $num;
}
I used the _getCellText method to pull out data from the screen in this format - "($294,098)" There is a _stringFilter() in the imported one.sah which strips the chars and retrieves the value as -294098 (Brackets indicate a negetive value).
It'd be great if someone could help me and let me know where I am goofing up. I seem to be getting issues with the _set method.
Here is the code:
_include("one.sah");
var $a=0;
var $b=0;
var $z=0;
var $aa=0;
var $bb=0;
var $zz=0;
// This function is working fine..
function _navigateToAlphaAndLogin($username,$password,$customer,$opportunity)
{
_setValue(_textbox("username"),$username);
_click(_submit("Login"));
_click(_link($customer));
_click(_link($opportunity));
_click(_link("Formula Rated Version"));
}
_navigateToAlphaAndLogin("sree","sree","De Paul University","JMeter-Sngl-Med-Assn-09/10/08 13:35:41");
//MARK: value a
// This assert works fine.There is a value coming in.
_assertEqual("($294,098)", _getText(_cell(_table(10), 11, 1)));
// Something missing here........
_set($aa, _stringFilter(_getText(_cell(_table(10), 11, 1))));
alert($aa);
$a= _stringFilter($aa);
//MARK: value b
_set($bb,_getCellText(_cell(_table(10), 12, 1)));
$b= _stringFilter($bb);
//MARK: value z
_set($zz, _getCellText(_cell(_table(10), 13, 1)));
$z= _stringFilter($zz);
_alert($a+$b);
//validation
_assertEqual($z, $a+$b);
//one.sah
function _stringFilter (s) {
//s = replaceChars(s);
if(s.charAt(0)=='('){
s = s.replace("(","-");
}
filteredValues = "$%)," ; // Characters stripped out
var i;
var returnString = "";
for (i = 0; i < s.length; i++) { // Search through string and append to unfiltered values to returnString.
var c = s.charAt(i);
//input.value = s;
if (filteredValues.indexOf(c) == -1)
returnString += c;
}
var $num = new Number(returnString);
alert($num);
return $num;
}
Comments
var $string = _getText(_cell(_table(10), 11, 1)));
$string = _stringFilter($string);
_set($aa, $string);
Do this: In your code, if you had also defined the function _stringFilter inside <browser></browser> tags, your code would have executed fine.
_set will make a string of whatever is passed to it and execute it on the browser. Since _stringFilter was not found on the browser, it failed.
Btw, you would save some confusion to other readers and yourself if you don't prefix your custom methods with _.
Cheers
Narayan
stringyLow,
I tweaked your bit and it works fine how. This is what I have now. Essentially, what you have suggested, but with a minor change.
_set($strin, _getText(_cell(_table(10), 11, 1)));
var $a=0;
$a= _stringFilter($strin);
Pankaj,
This is a P&L kind of page. So the figures come as ($345,687,98.09) - the brackets indicating negetive sign. To use parseInt(), shouldn't the first digit be a numeral?
Narayan,
Thanks for the code bit. I had tweaked stringyLow's bit and had stumbled upon the solution. But thanks for explaining the error and solution and for giving the complete code. One q though. Is there a suggested path for working on this? I meant some good documenataion and some examples. I have a couple of javaScript books with me and I'd really hate to use this forum for trivial doubts. I'd like to get a reasonable grasp of the functionalities of the tool before I hand it over to my testing team. I could write some test cases for arithmetic validations but am looking at some pagination tests now - like how do I go to the next page looking for a particular item.
regards
You are right but I think your _stringFilter() function is stripping the undesired characters from it. So you can use it after proper manipulation.
Regards,
Pankaj.
I see what u are saying. I'll use the function there to validate.
One more q. What is the best way to do this? I am serching for an item on page . if not found, it should go to the next page and so on, till the item is found. The script works, till the item is found on the page and then the assert fails. I am not sure whether _assertNotExists is the right condition to be used here.
while(_condition(_assertNotExists(_link("someItem"))))
{
//go to the next page till this item is found
_click(_link("Next"));
}
_assertExists(_link("someItem"));
_click(_link("someItem"));
As far as I have seen asserts don't return any value. So using them in the conditions won't help.
See if the below piece of code can help you: and if this doesnt help try this: Here you may have to think how to log if the link doesnt exist at all.
Regards,
Pankaj.