Please note that Sahi's development and support teams do not actively monitor this. This is more a community forum. If you are a Sahi Pro user looking for commercial support, please email support @ sahipro.com with your query.

Test broken links on a webpage

YashrajYashraj Members
edited January 10 in Sahi Pro
Hi could you please help me with finding all the links on a web page and testing if they're broken or not.
I found this code on the sahi community forum and edited it a little bit but seems not be working.
I'm completely new to sahi pro and still trying to figure out the tool. I've created similar script previously but using different automation tool.

/***************************Broken Link********************************/

function getLinks(){
var links = window.document.links;
var store = [];
for (var i=0; i<links.length; i++){
store[store.length] = {text:_sahi._getText(links), url:links.href};
_log(store);
}
return store;
}

function testBrokenLinks(){
_set($links, getLinks());
_log("Test1");
for (var $j=0; $j<$links.length; $j++){
_log("Test");
_navigateTo($links[$j].url);
_wait(10000, _sahi.loaded);
if (_condition(_containsText(document.body, "Either the remote server is down or not reachable"))){
_log($links[$j].text + " (" + $links[$j].url + ") is broken", "failure");
}else{
_log($links[$j].text + " (" + $links[$j].url + ") is fine", "success");
}
}
_log("Test2");
}

I'll be calling these two functions in the script.
Any help would be really appreciated.
Sign In or Register to comment.