Handle Dynamic Links Generation

I am running test case on web where i need to handle dynamic link generation, For static one i did that but every time i need to change it. if someone has done work on that can share insight

3 Likes

Yes — this is a very common Katalon pain point, especially when links or IDs are generated fresh every run.

The clean way to handle it is: do not keep editing the object manually every time.
Instead, make the locator dynamic/parameterized or build it at runtime.

Katalon’s docs recommend using relative XPath for dynamic elements and parameterized test objects when part of the locator changes between runs.

What usually happens with dynamic links

A link may look like this today:

<a href="/quote/12345/details">Open</a>

and next run it becomes:

<a href="/quote/67890/details">Open</a>

If your object is based on the full exact href, it will break every time.

So instead of this:

//a[@href='/quote/12345/details']

use one of these approaches.


Best approach 1: Use a stable part of the locator

If the link has fixed text or a fixed part in href, use that.

Example

//a[contains(@href,'/quote/') and contains(@href,'/details')]

or if link text is stable:

//a[normalize-space()='Open']

or combine both:

//a[contains(@href,'/quote/') and normalize-space()='Open']

This is usually the best and simplest solution.

Katalon also recommends relative XPath over absolute XPath for dynamic elements because absolute paths break easily when page structure changes.


Best approach 2: Parameterize the Test Object in Object Repository

This is the proper Katalon-style solution when only part of the locator changes.

In Object Repository

Create your test object with XPath like this:

//a[contains(@href,'${dynamicPart}')]

or:

//a[@href='${fullLink}']

Then in your test case:

TestObject dynamicLink = findTestObject('Object Repository/Page_Name/lnk_dynamic', [
    ('dynamicPart') : '/quote/12345/details'
])

WebUI.click(dynamicLink)

If you want exact full link:

TestObject dynamicLink = findTestObject('Object Repository/Page_Name/lnk_dynamic', [
    ('fullLink') : '/quote/12345/details'
])

WebUI.click(dynamicLink)

Katalon supports this ${variable} style parameterization for dynamic object properties.


My recommendation for you

In Katalon, the best maintainable solution is usually:

  1. Inspect the link and find the part that stays constant

  2. Build a relative XPath

  3. If one value changes every run, make it parameterized

  4. If value is known only during execution, build the object in script

That way you stop editing the locator every time manually.

2 Likes

could you pls share how does it look like ?

2 Likes

kindly share your outer html/dom if its not sensitive enough to share

Worked on Similar thing, Study about Data Driven Development.
I guess your question is about generating instead of Getting or click it on Element from DOM.

The best approach is either use Profiles, Or CSV, if the data is coming directly integrate Web Service.

Let me know if it fits.

3 Likes

Yes it is about sending data on link but dynamically.

Yes Passing Dynamic Data solve it, It was limited on data so used array for that and issue is sorted will see if need to make it CSV. Thanks to everyone who replied on my question.

2 Likes