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.
Test broken links on a webpage
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.
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.