Web ID Error - web Element not found?

I’m running into errors with one page opening in one test, but that same page is not opening in other tests.

I keep getting this error in my failed tests: Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Page_’ located by ‘//a[@id=‘LiverpoolTheme_wt9_block_wtMenu_DynamicMenuModule_wt13_block_wtMenus_wt4_RichWidgets_wt47_block_wtMenuItem_wt62’]’ not found

I tried to troubleshoot using the Katalon Q&A forum, but my update doesn’t seem to have fixed anything.

1 Like

To resolve the WebElementNotFoundException in Katalon when an element works in one test but fails in others:

1. Fix Locator Issues

Check for Dynamic IDs

The error //a[@id='LiverpoolTheme_wt9_block_wtMenu...'] suggests a dynamic ID (e.g., auto-generated by frameworks like GWT). These IDs change across sessions, so avoid using them. Instead:

  • Use a relative XPath/CSS selector with stable attributes (e.g., text, class, data-testid):

groovy

//a[contains(@class, 'menu-item') and text()='Home']
  • Re-spy the element in Katalon Studio to confirm if the ID has changed.
    • Right-click the object → Update Selected.

Verify Object Repository Path

Ensure the object’s path in the Object Repository matches the current page structure.

  • Example:
    :cross_mark: Incorrect Path: Page_OldName
    :white_check_mark: Correct Path: Page_NewName

2. Handle Timing/Page Load Issues

Add explicit waits to ensure the element is loaded:

groovy

WebUI.waitForElementPresent(findTestObject('Object Repository/Page/YourElement'), 30)
WebUI.click(findTestObject('Object Repository/Page/YourElement'))

3. Check for Context Changes

If the page opens in a new tab/iframe and the context isn’t switched:

  • For new tabs/windows:

groovy

WebUI.switchToWindowTitle('Page Title')
  • For iframes:

groovy

WebUI.switchToFrame(findTestObject('Object Repository/iframe'), 10)
// Perform actions
WebUI.switchToDefaultContent() // Exit iframe

4. Debugging Steps

Run in Debug Mode

Set breakpoints and step through the test to inspect the page state when the error occurs.

Capture Screenshots

Add screenshots before the failure:

groovy

WebUI.takeScreenshot()

Check Network/Console

Add code to log browser console errors:

groovy

String consoleLog = WebUI.executeJavaScript('return JSON.stringify(console.log)', null)
println "Console Log: $consoleLog"

5. Optimize Katalon Settings

  • Increase Timeout: Go to Settings > WebUI > Default Timeout (set to 30+ seconds).
  • Disable Smart Wait: In some cases, Settings > WebUI > Enable SmartWait can conflict with dynamic content.

6. Page URL/Flow Consistency

Ensure the test navigates to the correct URL and follows the same steps:

groovy

// Navigate explicitly
WebUI.navigateToUrl('https://your-app.com/page')

7. Update Dependencies

  • Upgrade Katalon to the latest version.
  • Reinstall or update the Multi-Level Shadow DOM Plugin if shadow DOM is involved.

Example Fix

Before (using dynamic ID):

groovy

WebUI.click(findTestObject('Object Repository/Page_/DynamicIdElement'))

After (using stable attributes):

groovy

// Object defined with XPath: //a[contains(text(), 'Submit')]
WebUI.waitForElementPresent(findTestObject('Object Repository/Page_/SubmitButton'), 30)
WebUI.click(findTestObject('Object Repository/Page_/SubmitButton'))

As @dineshh says, you should put in a wait statement to ensure your object is available to be interacted with. However, I may use:

WebUI.waitForElementVisible(findTestObject('...'), 10)
WebUI.verifyElementVisible(findTestObject('...'))

WebUI.click(findTestObject('...'))

and for your dynamic variables, you could use the xpath functions: contains or starts-with to pull apart any <id> that are not characters, like:

xpath = //a[starts-with(@id,'LiverpoolTheme_wt') and contains(@id, 'block_wtMenu_DynamicMenuModule_wt') and contains(@id, 'block_wtMenus_wt') and contains(@id, 'RichWidgets_wt') and contains(@id, 'block_wtMenuItem_wt')]

Edit: if you only use the Web Recorder or Web Spy, then this is where you need to spend time to learn how to build these pathways as neither of these tools can do it.

I would also look for other attributes that may be stable, such as name or aria-id. These only have to be unique for the page.

xpath = //input[@name = 'YearGroup_StartDate']

Edit2:

This message looks like the element is not finished or has been messed with. Can you hover over the object in your code and then using CTRL + mouse click to see if anything opens? If nothing opens, then this is not an item in your Object Repository.