How to validate web page link is broken or not?


I was able to get all the link URL in a web page. I want to know,

  1. how to get the name of the link
  2. how to validate link URL is broken(404) or accessible(200)

Glad if anyone help me on this.


Q2 first. Did you try…

As for Q1, when you say “name” what do you mean? <a href=...> elements don’t usually have a name attribute.

You can retrieve the value of any attribute though.


with native selenium, check this page

Thanks Thomas for your reply.

Q2: I am getting a stepfailedException.

I have set up the test as below,

For Q1:
I can get the url of those links, but how can I get the link names?


Unfortunately for you, the developers of your page have not used recognized standards to construct links. Links are HTML <a> elements that look something like this:

<a href="https://...">some text</a>

The href attribute informs the browser where to link to.

Your page uses this non-standard approach:

<a href="#">

This means when you try to use verifyLinksAccessible, WebDriver can’t verify the links since, in effect, they don’t exist.

Back to Q1: I still don’t know for sure what you mean by “how can I get the link name?”

Assuming you mean the text within the <a>...</a> element, try to use WebUI.getText(). But again, the developers may be doing something odd with the <span> which I can’t see from your screenshot.

i may misunderstood a bit the topic.
for me, to verify if a link is accesible means it is clickable …
to verify if the link is broken or not (returns 200 or > 400 response code) you can simply make a get request, provided you have the url, using the Webservice API.
not sure if it helps …

Sure. But that’s not the same as verifying the link works <- the thing a user would do. You’re verifying an endpoint is responding.

No doubt, there is JavaScript behind that <a> tag, but since it’s Chrome it’s considered “secret” :roll_eyes:

agreed. this is why we may have to detail a bit on the ‘accesibility’ from the OP point of view.
for me it can also mean that ‘it is readable by screen readers and can be accessed by using keyboard only’

(yeah, for a while i had to do that kind of accesibility testing … and it is a pain in the ass, cannot be automated)

so, sometime, splitting the problem in smaller pieces may help

imho, there is no point to actualy check how a click on the ‘rendered link’ is behaving, if the target url is not valid, unless is subject for negative testing.

1 Like

Thanks bionel for your reply. Could you please tell me more about Webservice API, where I can find them? I tried to find groovy method/programs that can be used to get response code, but still no luck.

I am using following code in UFT. Can I use it in Katalon with groovy?

Set objWinHTTP = CreateObject(“WinHttp.WinHttpRequest.5.1”)
objWinHTTP.Open “GET”, sURL, False
objWinHTTP.SetRequestHeader “User-Agent”, “Mozilla/4.0 (compatible; MyApp 1.0; Windows NT 5.1)”
iReturnVals = objWinHTTP.Status

@thushar.ameen see the docs, you have already provided objects and keywords for such requests:

will be a bit tricky, since mostly your project is started with the web template, but you can use also the webservice objects into it

see also:

After successfully login, when I am trying to get working urls using code:
@When(“Collect all the links in the web page based on ‘a’ tag”)
def collect_links() {

	List<String> allURLs = WebUI.getAllLinksOnCurrentPage(true, [])
	println ('Total links on page: ' +allURLs.size())
	for(String aURL : allURLs) {
		println aURL;

Getting below errors:
Login Sucessfully true
2020-03-24 06:05:18.547 DEBUG c.k.k.c.c.keyword.CucumberReporter - ✓ I am at home page
2020-03-24 06:05:18.550 DEBUG c.k.k.c.c.keyword.CucumberReporter - STEP Collect all the links in the web page based on ‘a’ tag
Total links on page: 39
2020-03-24 06:05:21.920 ERROR c.k.k.core.keyword.internal.KeywordMain - :x: Unable to send request (Root cause: No X509TrustManager implementation available
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(
at org.apache.http.impl.execchain.MainClientExec.establishRoute(
at org.apache.http.impl.execchain.MainClientExec.execute(
at org.apache.http.impl.execchain.ProtocolExec.execute(
at org.apache.http.impl.execchain.RetryExec.execute(
at org.apache.http.impl.client.InternalHttpClient.doExecute(
at org.apache.http.impl.client.CloseableHttpClient.execute(
at com.kms.katalon.core.webservice.common.RestfulClient.response(
at com.kms.katalon.core.webservice.common.RestfulClient.sendRequest(
at com.kms.katalon.core.webservice.common.RestfulClient.send(
at com.kms.katalon.core.webservice.keyword.builtin.SendRequestKeyword$_sendRequest_closure1.doCall(SendRequestKeyword.groovy:42)
at com.kms.katalon.core.webservice.keyword.builtin.SendRequestKeyword$
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.webservice.keyword.builtin.SendRequestKeyword.sendRequest(SendRequestKeyword.groovy:38)
at com.kms.katalon.core.webservice.keyword.builtin.SendRequestKeyword.execute(SendRequestKeyword.groovy:33)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.builtin.VerifyLinksAccessibleKeyword$_verifyLinksAccessible_closure1.doCall(VerifyLinksAccessibleKeyword.groovy:42)
at com.kms.katalon.core.webui.keyword.builtin.VerifyLinksAccessibleKeyword$
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
at com.kms.katalon.core.webui.keyword.builtin.VerifyLinksAccessibleKeyword.verifyLinksAccessible(VerifyLinksAccessibleKeyword.groovy:37)
at com.kms.katalon.core.webui.keyword.builtin.VerifyLinksAccessibleKeyword.execute(VerifyLinksAccessibleKeyword.groovy:32)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:72)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyLinksAccessible(WebUiBuiltInKeywords.groovy:3723)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyLinksAccessible$ Source)
at progression.StudentPortalLinkVerification.collect_links(StudentPortalLinkVerification.groovy:31)
at cucumber.runtime.Utils$
at cucumber.runtime.Timeout.timeout(
at cucumber.runtime.Utils.invoke(
at cucumber.runtime.PickleStepDefinitionMatch.runStep(
at cucumber.runner.TestStep.executeStep(
at cucumber.runner.Runner.runPickle(
at cucumber.runtime.Runtime.runFeature(
at cucumber.api.cli.Main$ Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy:76)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$_runFeatureFile_closure1.doCall(CucumberBuiltinKeywords.groovy)
at com.kms.katalon.core.keyword.internal.KeywordMain.runKeyword(KeywordMain.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordMain$ Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:46)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$runFeatureFile$0.callStatic(Unknown Source)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords.runFeatureFile(CucumberBuiltinKeywords.groovy:169)
at com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords$ Source)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(
at com.kms.katalon.core.main.WSVerificationExecutor.runScript(
at com.kms.katalon.core.main.WSVerificationExecutor.doExecute(
at com.kms.katalon.core.main.WSVerificationExecutor.processExecutionPhase(
at com.kms.katalon.core.main.WSVerificationExecutor.accessMainPhase(
at com.kms.katalon.core.main.WSVerificationExecutor.execute(
at com.kms.katalon.core.main.TestCaseMain.runFeatureFile(
at com.kms.katalon.core.main.TestCaseMain$runFeatureFile$ Source)
Caused by: No X509TrustManager implementation available
… 61 more

And html is also standard:

you are missing ssl certification
your urls are using ssl certification
ouh and here you have typo
for(String aURL : allURLs) {
println aURL;
should be