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.
How do I get a list of links in the page
The following piece of code does not work :
I also tried something similar to the example at http://sahi.co.in/w/for-loops
(btw the example does not work since getLinkIds() function is not defined )
If I add
before the for loop, it reports
but does not get into the loop. The first log message in the loop is not printed.
What am I doing wrong ?
for (var i = 0; i < document.links.length; i++)
{
var a = document.links[i];
if(a.indexOf("somesite.com")>0)
_alert("Hey.. somesite.com ");
}
I also tried something similar to the example at http://sahi.co.in/w/for-loops
(btw the example does not work since getLinkIds() function is not defined )
If I add
_log("Num Links = " + document.links.length);
before the for loop, it reports
Num Links = 16
but does not get into the loop. The first log message in the loop is not printed.
What am I doing wrong ?
Comments
You will get an example that meets your requirement from the following thread
http://sahi.co.in/forums/viewtopic.php?id=1028
What I want to do is to get the value of the href for each of these links.
When running the following code
I get
where as if I check the Page Source I can see
i.e. the value of the urls for the href attribute are relative in the source whereas links[$i].href gives me the absolute url.
Is there a way for me to get the actual value for href attribute instead of the full link ?
For relative urls, this the behaviour:
If the url of your page is "http://localhost:8180/abcd/index.htm"
and your link is
link.href = "http://localhost:8180/abcd/link1.jsp"
link.pathname = "/abcd/link1.jsp";
link.attributes["href"].value = "link1.jsp" (in firefox)
link.attributes["href"].value = "http://localhost:8180/abcd/link1.jsp" (in IE)
Regards,
Narayan