Web Testing Category
Do you ever face Web elements fail during execution even though they were previously working? Have you faced this Dynamic Elements Not Identified? How to solve and fix this
Web Testing Category
Do you ever face Web elements fail during execution even though they were previously working? Have you faced this Dynamic Elements Not Identified? How to solve and fix this
This is a very common real-world automation problem — especially in modern web apps (React, Angular, Vue, dynamic DOM refresh, lazy loading, etc.).
Since you’re already experienced in Katalon + automation, I’ll explain this in a practical, framework-level way, not basic theory.
Even though they worked earlier, failures usually happen because of:
Dynamic DOM refresh (React/Angular re-render)
Element ID changing dynamically
Timing issues (element not ready yet)
Shadow DOM
Iframe loading late
Stale element reference
AJAX / API-based delayed rendering
Index-based XPath
Environment speed differences (local vs CI)
Bad XPath:
//*[@id="mat-input-123"]
Index-based:
(//button)[3]
These WILL break.
Use:
data-testid
data-qa
aria-label
stable class combinations
visible text (when stable)
Example:
//button[normalize-space()='Submit']
or
//*[@data-testid='login-button']
If your dev team doesn’t provide stable attributes → ask them to add data-testid.
This is industry best practice.
In Katalon:
WebUI.waitForElementVisible(findTestObject('Page/Login/btn_Login'), 20)
WebUI.waitForElementClickable(findTestObject('Page/Login/btn_Login'), 20)
Never directly click without wait.
Bad:
WebUI.click(obj)
Good:
WebUI.waitForElementClickable(obj, 20)
WebUI.click(obj)
If page uses AJAX:
Instead of waiting for element directly:
WebUI.waitForJQueryLoad(20)
WebUI.waitForPageLoad(20)
Or custom wait:
WebUI.waitForElementPresent(obj, 20)
If dynamic part changes:
Example:
Order #12345
Order #67890
Use:
//div[contains(text(),'Order #')]
or
//div[starts-with(text(),'Order #')]
If element re-renders:
Solution → Retry logic
Example:
int retry = 0
while(retry < 3){
try{
WebUI.click(obj)
break
} catch(Exception e){
WebUI.delay(2)
retry++
}
}
Better → create custom reusable keyword for retry click.
Instead of:
(//input)[4]
Use:
//label[text()='Email']/following::input[1]
This survives DOM structure changes.
Always switch:
WebUI.switchToFrame(findTestObject('iframe_object'), 10)
After work:
WebUI.switchToDefaultContent()
Katalon default object spy may fail.
Use JavaScript:
WebUI.executeJavaScript(
"return document.querySelector('custom-element')
.shadowRoot.querySelector('button')", null)
Enable:
Project Settings → Execution → WebUI → Smart Wait → Enable
This helps with dynamic rendering.
When element fails:
Pause execution
Open browser dev tools
Inspect if:
Element really present?
Inside iframe?
Hidden?
Disabled?
Different DOM?
Create reusable wrapper methods:
Example:
def safeClick(TestObject obj) {
WebUI.waitForElementClickable(obj, 20)
WebUI.scrollToElement(obj, 10)
WebUI.click(obj)
}
Never call WebUI.click directly in test cases
Use centralized custom keywords
Add logging
Add retry
Add screenshots on failure
Use Dynamic TestObject creation:
TestObject dynamicObj = new TestObject()
dynamicObj.addProperty("xpath",
ConditionType.EQUALS,
"//div[text()='${dynamicValue}']")
Create a reusable WebUI utility class
Never depend on Spy-generated locators blindly
Enforce locator strategy standards in your project
I think @arvind.choudhary has given you an excellent post on your issue, but I also have one more. If you are doing regression testing on your application, you may encounter actual reference changes to elements (maybe because the developers want to implement brand new javascript to apply to the piece). In this case, there is nothing you can do except to change your pathway (or identifier). So, you are going to get some “failures” in this case–can I suggest setting your default “FailureHandling” to OPTIONAL and then fixing/investigating the “failures” later.
There is no magical way you can apply easily. You would need to struggle for yourself.
If you want to ask others for help, you need to disclose a lot more information to us. Sharing concrete information will make your problem resolvable for others. You need to disclose sufficient information to be understood by others. Please make efforts to describe your problem with concrete information.
Too much works? — yes, it is much. It is always tiring to make a good question on the net.
Unless you disclose enough information, I can not make any suggestion like “do this, do that”.
See also
Hi @stevio052002, I saw your question under a category explanation, hence I separated it to bring more attention for our community to support you. It would be great if you could share your problem in details to get faster solutions. Thanks!
Yes, As he asked the generic question, so answers pouring in are also generic.