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.
For Loop help
Hello,
I'm brand new to Sahi. I saw the flash demo and thought this is a really cool testing software. I've been trying out some of the sample code on the site, but I can't seem to get things working. I copied and pasted the code for the For Loop, but I get a Failure when I execute the script.
Heres the contents of my script:
---Begin Script---
var $searchTerm = "asdf";
_setValue(_textbox("q"), $searchTerm);
_click(_submit("Google Search"));
var $anchors = [];
function getLinks(){
var retVal = [];
var links = document.links;
for (var i=0; i<links.length; i++){
retVal = links.innerHTML;
}
return retVal;
}
_set($anchors, getLinkIds());
for (var $i=0; $i<$anchors.length; $i++) {
_alert($anchors);
}
---End Script---
I get the following output in my Statements box:
_setValue(_textbox("q"), "asdf");
_click(_submit("Google Search"));
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
--Stopped Playback: FAILURE--
Does anyone have any clue whats wrong with my script?
And is this a typo?
_set($anchors, getLinkIds()); //Shouldn't it be getLinks()? Regardless, I still get the same error.
Any feedback/help would be greatly appreciated. Thanks!
I'm brand new to Sahi. I saw the flash demo and thought this is a really cool testing software. I've been trying out some of the sample code on the site, but I can't seem to get things working. I copied and pasted the code for the For Loop, but I get a Failure when I execute the script.
Heres the contents of my script:
---Begin Script---
var $searchTerm = "asdf";
_setValue(_textbox("q"), $searchTerm);
_click(_submit("Google Search"));
var $anchors = [];
function getLinks(){
var retVal = [];
var links = document.links;
for (var i=0; i<links.length; i++){
retVal = links.innerHTML;
}
return retVal;
}
_set($anchors, getLinkIds());
for (var $i=0; $i<$anchors.length; $i++) {
_alert($anchors);
}
---End Script---
I get the following output in my Statements box:
_setValue(_textbox("q"), "asdf");
_click(_submit("Google Search"));
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
setServerVar('\$anchors', getLinkIds());
--Stopped Playback: FAILURE--
Does anyone have any clue whats wrong with my script?
And is this a typo?
_set($anchors, getLinkIds()); //Shouldn't it be getLinks()? Regardless, I still get the same error.
Any feedback/help would be greatly appreciated. Thanks!
Comments
Use this code The function getLinkIds() acts on the page's DOM so it needs to be in the <browser> </browser> tags. Also the function name in the definition and the function call should obviously be same.
Regards,
Pankaj.
var $searchTerm = "java";
_setValue(_textbox("q"), $searchTerm);
_click(_submit("Google Search"));
_alert(document.links.length);
where as the following code is showing error as 'JSERROR ReferanceError."document"is not defined'
var $searchTerm = "java";
_setValue(_textbox("q"), $searchTerm);
_click(_submit("Google Search"));
var linkarr=[];
linkarr=document.links;
_alert(linkarr.length);
Why it is so ?