Forum Discussion
- tristaanogreEsteemed Contributor
A little bit more information will be helpful. What sort of code are you running that gets that error? What are you testing? There could be any number of reasons for the error but without more details, we're pretty much blind here.
- mttsowOccasional Contributor
Hi Robert,
I am trying to check broken link.
I found the sample code in smartbear site and try running it.
It errored out on the switch statement, trying to get httpObj.status.
function VerifyWebObject(link, expectedObjectData)
{
var httpObj = Sys.OleObject("MSXML2.XMLHTTP");
httpObj.open("GET", link, true);
httpObj.send();
while (httpObj.readyState != 4 && httpObj.readyState != 1)
Delay(100);
switch (httpObj.status)
{
case 200:
case 302:
if (httpObj.responseText != expectedObjectData)
{
Log.Message("The " + link + " link is valid", httpObj.responseText);
return false;
}
break;
default:
Log.Message("The " + link + " link was not found, the returned status: " + httpObj.status, httpObj.responseText);
return false;
}
return true;
}
function Test()
{
var page = Sys.Browser("*").Page("*");
var expectedObjectData = "";
// Obtains the links
var links = page.contentDocument.links;
var linksCount = links.length;
if (linksCount > 0)
{
// Searches for broken links
for (var i = 0; i < linksCount; i++)
{
var link = links.item(i);
var URL = link.href;
Log.Message("The " + URL + " verification results: " + VerifyWebObject(URL, expectedObjectData));
}
}
}
Thanks
Mary
- tristaanogreEsteemed Contributor
Just out of curiousity, did this work at one point in time and just stop working recently? Or is this your first attempt at executing that particular code?
I'm thinking, based upon my limited understanding (it's been a looooong time since I've messed with these objects) is that your inclusion of the httpObj.Send() call might be what's screwing things up. You have the open request which should be a sufficient request to get what's at the URL. Have you tried removing that send call?
An alternative... and thanks to LinoTadros for showing me this trick at SmartBear connect... look into using the WebAccessibility checkpoint. You can limit those checkpoints to only check link access so, with basically one line of code, you can get a quick report of which links work and which ones don't.
Related Content
- 7 years ago
- 5 years ago
Recent Discussions
- 3 days ago