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.
Count of links in a page
Hi Guys,
I am using the below code to count no of links in a page
and i am using the if condition to compare the link text and
if it matches i want to execute the code in the if condition
but the its not working can anyone please help me in this
var $anchors = [];
function getLinkIds()
{
var retVal = [];
var links = document.links;
for (var a=0; a<links.length; a++)
{
retVal [a]= links[a].innerHTML;
}
return retVal;
}
_set($anchors, getLinkIds());
for (var $a=0; $a<$anchors.length; $a++)
{
if (_condition(( "Claims Status" == _getText(_link(a)))))
{
_click(_link("Claims Status"));
}
}
I am using the below code to count no of links in a page
and i am using the if condition to compare the link text and
if it matches i want to execute the code in the if condition
but the its not working can anyone please help me in this
var $anchors = [];
function getLinkIds()
{
var retVal = [];
var links = document.links;
for (var a=0; a<links.length; a++)
{
retVal [a]= links[a].innerHTML;
}
return retVal;
}
_set($anchors, getLinkIds());
for (var $a=0; $a<$anchors.length; $a++)
{
if (_condition(( "Claims Status" == _getText(_link(a)))))
{
_click(_link("Claims Status"));
}
}
Comments
I will look at this problem more closly tomorrow, but just by reading the code now, I would say that you have to declare arrays by
var $sampleArray= new Array();
I don't know if this is really needed, but thats how I remember working with Arrays.
Also I m not sure if _set($anchors, getLinkIds()); works as you expect, i would write a
_set($anchors[a], links[a].innerHtml);
into the getLinkIds() function. Please excuse me when I'm telling bullshit, I can't test it right now
Does the Sahi logs say anything about what went wrong?
_sahi.setServerVar('\$anchors', getLinkIds());
TypeError: Object expected
No trace available
var $arr1= new Array();
var $arr2= new Array();
function set(){
for (var $i=0; $i<10; $i++ ) {
$arr1[$i] = $i*4;
}
return $arr1
}
_set($arr2, set());
////// create 2 testarrays, fill one up with some numbers, try the _set() API to copy the values to $arr2
Error: _sahi.setServerVar('\$arr2[\$i]', set());
ReferenceError: set is not defined
While this is working fine:
var $arr2= new Array();
var $arr1= new Array();
function set(){
for (var $i=0; $i<10; $i++ ) {
$arr1[$i] = $i*4;
_set($arr2[$i], $arr1[$i])
}
}
set();
so please try to change your code as I mentioned the post before.
Regards
Wormi
You seem to want to click on all links with text "Claims Status".
You could use this:
You could also do the same with:
Hope that helps.
Regards,
Narayan