# How to get and verify links within a certain object

**URL:** <https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [October 2, 2017, 9:54am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625 "2017-10-02T09:54:51Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![K\_Alsemgeest](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@K\_Alsemgeest](https://forum.katalon.com/u/K_Alsemgeest)\
**Post date:** [October 2, 2017, 9:54am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/1 "2017-10-02T09:54:51Z")

</div>

I only want to get and verify all links accessible in the footer (object= footer\_wrapper clearfix) of this page: [https://www.universiteitleiden.nl/en/education](https://www.universiteitleiden.nl/en/education).

I found the keyword to getAllLinksOnCurrentPage, but that’s to much. Please advice.

---

<div class="post-metadata">

**Author:** ![Hanh\_Tran](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/hanh_tran/32/651_2.png) [@Hanh\_Tran](https://forum.katalon.com/u/Hanh_Tran)\
**Post date:** [October 3, 2017, 8:34am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/2 "2017-10-03T08:34:59Z")

</div>

1. Create a new test object contains selector to these link, such as //div[@id=footer].

2. In your test case, uses the following code to get all links from above object.

This will return all links within that object

---

<div class="post-metadata">

**Author:** ![K\_Alsemgeest](https://avatars.discourse-cdn.com/v4/letter/k/3e96dc/32.png) [@K\_Alsemgeest](https://forum.katalon.com/u/K_Alsemgeest)\
**Post date:** [October 17, 2017, 6:22am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/3 "2017-10-17T06:22:28Z")

</div>

It’s not working yet. The code isn’t giving any errors, but it doesn’t get the URL’s either. This is my code:

```
WebElement element = WebUiCommonHelper.findWebElement(findTestObject('Object Repository/STW_footer/ul'), 
    30)

List URLs = element.getAttribute('href')

WebUI.verifyLinksAccessible(URLs)

```

I tried existing objects and making a new object, but with no result. I also don’t have something like an id=footer somewhere in the code. I only have classes like class=footer-container and / or class=wrapper clearfix, but none of these work.

I want to get all URL’s within the footer on this page ([https://www.universiteitleiden.nl/en/education.)](https://www.universiteitleiden.nl/en/education.)) and verify if the links are accessible. Please help with the last pieces of this puzzle. Thanks.

---

<div class="post-metadata">

**Author:** ![rafael\_quinones](https://avatars.discourse-cdn.com/v4/letter/r/73ab20/32.png) [@rafael\_quinones](https://forum.katalon.com/u/rafael_quinones)\
**Post date:** [January 24, 2018, 6:05pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/4 "2018-01-24T18:05:52Z")

</div>

Hello, how can i get the response status code of a URL, not a object?

I’m using this keyword:

links = WebUI.getAllLinksOnCurrentPage(true, [])

for (url in links) {

println(url)

}

I want to get the status code of each URL string (ex: 200, 404)

Thanks

---

<div class="post-metadata">

**Author:** ![Joan\_Antoni](https://avatars.discourse-cdn.com/v4/letter/j/bb73d2/32.png) [@Joan\_Antoni](https://forum.katalon.com/u/Joan_Antoni)\
**Post date:** [February 15, 2018, 12:55pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/5 "2018-02-15T12:55:10Z")

</div>

> K. Alsemgeest said:
> 
> It’s not working yet. The code isn’t giving any errors, but it doesn’t get the URL’s either. This is my code:
> 
> ```auto
> WebElement element = WebUiCommonHelper.findWebElement(findTestObject('Object Repository/STW_footer/ul'), 30)List URLs = element.getAttribute('href')WebUI.verifyLinksAccessible(URLs)
> 
> ```
> 
> I tried existing objects and making a new object, but with no result. I also don’t have something like an id=footer somewhere in the code. I only have classes like class=footer-container and / or class=wrapper clearfix, but none of these work.
> 
> I want to get all URL’s within the footer on this page ([https://www.universiteitleiden.nl/en/education](https://www.universiteitleiden.nl/en/education).) and verify if the links are accessible. Please help with the last pieces of this puzzle. Thanks.

Hi!

Have you been able to get it?

Im trying to create the same script that u want but i don’t get it…

---

<div class="post-metadata">

**Author:** ![Rohith\_R](https://avatars.discourse-cdn.com/v4/letter/r/22d042/32.png) [@Rohith\_R](https://forum.katalon.com/u/Rohith_R)\
**Post date:** [June 28, 2018, 10:53am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/6 "2018-06-28T10:53:14Z")

</div>

Hi,

Is there a way to find the broken links using Katalon ?  
If so, can i able to upload the links from excel to katalon and validate?

---

<div class="post-metadata">

**Author:** ![Mirnesa](https://avatars.discourse-cdn.com/v4/letter/m/48db29/32.png) [@Mirnesa](https://forum.katalon.com/u/Mirnesa)\
**Post date:** [June 28, 2018, 12:26pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/7 "2018-06-28T12:26:36Z")

</div>

Hello,  
I would like to ask you about get and verify links within footer  
I tried link from documentation but it doesnt give me result, please any help , do you have any example how can automated ? Thank you

===

---

<div class="post-metadata">

**Author:** ![Shashikant\_M](https://avatars.discourse-cdn.com/v4/letter/s/a5b964/32.png) [@Shashikant\_M](https://forum.katalon.com/u/Shashikant_M)\
**Post date:** [July 11, 2018, 10:56am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/8 "2018-07-11T10:56:51Z")

</div>

Here is the code i wrote for Getting all the links in Footer :

@Keyword

public ArrayList verifyFooterSection(String divID) {

KeywordUtil.logInfo(“Get all Footer links”)

String ModifiedString="";

ModifiedString=divID.toLowerCase();

ListActualFooterLinks=new ArrayList();

WebElement element = driver.findElement(By.id(ModifiedString));

List options = element.findElements(By.tagName(“a”));

[//System.out.println](https://System.out.println)(options.size());

int ActualLinksSize = 0;

for (WebElement we : options) {

String strLinkName = we.getText()

//println strLinkName.isEmpty()

if (strLinkName == null || strLinkName.isEmpty()){

}else{

ActualFooterLinks.add(strLinkName)

ActualLinksSize=ActualLinksSize+1

println ActualLinksSize + " : Footer Link Name : " + strLinkName

}

}

//}

println ActualLinksSize

}

---

<div class="post-metadata">

**Author:** ![Bal\_Mukund](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@Bal\_Mukund](https://forum.katalon.com/u/Bal_Mukund)\
**Post date:** [February 2, 2019, 8:20pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/9 "2019-02-02T20:20:48Z")

</div>

@Shashikant_M  
@K_Alsemgeest

any of you guys can explain or give the solution to me?

I am getting errors using the methods explained here so far. Thanks

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [February 3, 2019, 3:14pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/10 "2019-02-03T15:14:18Z")

</div>

Hi @Bal_Mukund

Can you provide us with the description of the errors you are encountering ?

---

<div class="post-metadata">

**Author:** ![Bal\_Mukund](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@Bal\_Mukund](https://forum.katalon.com/u/Bal_Mukund)\
**Post date:** [February 3, 2019, 7:51pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/11 "2019-02-03T19:51:02Z")

</div>

@ThanhTo

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/f/f12be794516104c8f2cb28be5c71a500fcd3cf33.png)

this is the error I get, now i understand the problem but can not find a solution.

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [February 4, 2019, 6:50am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/12 "2019-02-04T06:50:29Z")

</div>

Hi @Bal_Mukund

It seems that `findWebElements` return an `ArrayList` and you are trying to pass it into an Object element. Please append `.get(0)` into the end of that line:

`element = findWebElements(findTestObject('pathToObject'), 20).get(0)`

Please note that this does not necessarily mean that your test will pass, because there’s a chance the XPath you are using may be wrong or the element you are trying to locate doesn’t appear after 20 seconds. In that case you will get an empty list and you should re-check your XPath or set a longer time out.

Have a nice day !

---

<div class="post-metadata">

**Author:** ![Bal\_Mukund](https://avatars.discourse-cdn.com/v4/letter/b/c68b51/32.png) [@Bal\_Mukund](https://forum.katalon.com/u/Bal_Mukund)\
**Post date:** [February 4, 2019, 7:21am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/13 "2019-02-04T07:21:31Z")

</div>

@ThanhTo my object xpath is correct, will make sure it stays so.  
please help me out with following:

1. VerifyLinksAccessible accepts list param and as you can see in the code below the getAttribute returns string ( i used it as was suggested in an answer above). How can I get a valid URL to pass on to VerifyLinksAccessible

WebElement element = WebUiCommonHelper.findWebElements(findTestObject(‘Object Repository/TextMatchingObjects/PreviewHref’), 20).get(0)

List URLs = element.getAttribute(‘href’)

WebUI.verifyLinksAccessible(URLs)

Or if you can guide me to create a custom keyword to get links from an object and verify if they are accessible. the getAllLinksOnCurrentPage gets all links from the page which increases test time. Or any feasible solution for this challenge

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [February 4, 2019, 7:27am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/14 "2019-02-04T07:27:40Z")

</div>

> [@Bal\_Mukund](#):
>
> List URLs = element.getAttribute(‘href’)

HI @Bal_Mukund

You can wrap an object with ` Arrays.asList` to convert it into a list, like this:  
`List URLs = Arrays.asList(element.getAttribute(‘href’))`

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [March 24, 2020, 5:05pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/15 "2020-03-24T17:05:01Z")

</div>

**I am using this script :**

List allURLs = WebUI.getAllLinksOnCurrentPage(true, )  
println ('Total links on page: ’ +allURLs.size())

```
	WebElement element = WebUiCommonHelper.findWebElement(findTestObject('Object Repository/Progression/Management/StudentPLinkVerification/MainMenuLinks'))
	List URLs = element.getAttribute('href')
	print URLs

```

Getting no error but result is coming null

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/c/ce0ce179e7b53b04884775d1067bc323230cbdfc.png)  
**HTML:**  
 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/f/f6a050ea800a36aaa115635e5e5b56c632194ee1.png)

**Adding locator-**  
.//\*[@class=“headerlinksdiv”]/span/map/p/table/tbody/tr/td/table/tbody/tr  
If i search in chrome , it highlights this navigation menu bar

 ![image](https://europe1.discourse-cdn.com/katalon/original/2X/e/ed5528c46be5e17ec449ba7cb2415e7e000311f1.png)

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [March 24, 2020, 5:41pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/16 "2020-03-24T17:41:06Z")

</div>

Please also provide the details of the Test Object (i.e Selected Locator). Can you throw that locator into Chrome’s DevTool to see if it correctly locates the a element.

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [March 24, 2020, 6:55pm UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/17 "2020-03-24T18:55:50Z")

</div>

added both , please refer

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [March 25, 2020, 3:23am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/18 "2020-03-25T03:23:16Z")

</div>

Hi @shilpi1

the locator

```auto
.//*[@class=“headerlinksdiv”]/span/map/p/table/tbody/tr/td/table/tbody/tr

```

doesn’t seem to locate the link, seeing that it ends with `tr` and not `a`. Please use Spy Tool to capture the link element and then use that as a Test Object instaed of this one.

---

<div class="post-metadata">

**Author:** ![shilpi1](https://avatars.discourse-cdn.com/v4/letter/s/b3f665/32.png) [@shilpi1](https://forum.katalon.com/u/shilpi1)\
**Post date:** [March 25, 2020, 8:08am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/19 "2020-03-25T08:08:27Z")

</div>

> [@ThanhTo](#):
>
> ```auto
> .//*[@class=“headerlinksdiv”]/span/map/p/table/tbody/tr/td/table/tbody/tr
> 
> ```

Note sure how else I can make generalised xpath, .//\*[@class=“headerlinksdiv”]/span/map/p/table/tbody/tr/td/table/tbody/tr/td  
I used it because inside last td tag is coming.. please suggest suggest  
  ![image](https://europe1.discourse-cdn.com/katalon/original/2X/3/3334b1db16064a1983713e18e11b27ec5b6a15ea.png)

---

<div class="post-metadata">

**Author:** ![ThanhTo](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/thanhto/32/697_2.png) [@ThanhTo](https://forum.katalon.com/u/ThanhTo)\
**Post date:** [March 25, 2020, 8:16am UTC](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625/20 "2020-03-25T08:16:52Z")

</div>

In the Dev Tools (the picture you posted), right click on the `a` element which contains the `href` attribute and choose Copy \> Copy XPath and use that instead.

[Next page](https://forum.katalon.com/t/how-to-get-and-verify-links-within-a-certain-object/6625.md?page=2)
