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 all Links of a page into a variable one by one
Hi,
Can any one one tell me how to get all the links present in a webtable.
Example : one coming to the Sahi forum page we get several posts in a web table.
Say I wanna capture all the links into a variable one by one.
Regards,
kaushik
Can any one one tell me how to get all the links present in a webtable.
Example : one coming to the Sahi forum page we get several posts in a web table.
Say I wanna capture all the links into a variable one by one.
Regards,
kaushik
Comments
You can get all the links in a web page into a variable like this: For extracting links specifically from a web table alone, I think more thinking would be needed
Regards,
Pankaj.
I Understand that taking values from the table requires more thinking and I will do it.
I am trying to get the names of the links on a message box. And following is the code
_setValue(_textbox("q"), "fhgfgh");
_click(_submit("Google Search"));
var $x = new Array();
_set($x, top.document.links);
_alert($x[1]);
But when I run this it throws an error. I dont know why can you help me on this.
For further reading go to:
http://sahi.co.in/w/scripting-changes-in-sahi-v2
Regards,
Pankaj.
_setValue(_textbox("q"), "bang");
_click(_submit("Google Search"));
_alert(getlinkname());
<browser>
function getlinkname(){
return (top.document.links[2]);
}
</browser>
Now It shows me the alert with the URL of the link and not the link name.
Have I done it the right way.
regards,
kaushik
Now You can fiddle around with the idea to get links from a web table.
All the best
Pankaj.
return (top.document.links[2].name);
Were you trying to get the text encapsulated by the link tags? In that case, you would want to use the innerHTML property
return (top.document.links[2].innerHTML);
You can read about it here:
http://www.w3schools.com/htmldom/prop_anchor_innerhtml.asp
You'll get more mileage out of Sahi if you familiarize yourself with the HTML Document Object Model.
http://www.w3schools.com/htmldom/default.asp