Unpredictable WebElementNotFoundException

Hi all,

My script fails due to WebElementNotFoundException randomly, but the application doesn’t change. I tried several waitFor commands and waitForPageLoad, but the result is an everything or nothing scenario. If it finds the element, it is present, clickable etc, but sometimes it is a deadend.
I need to use Internet Explorer, which is alone pain itself, furthermore I’m dealing with frames and pop-up windows.
There are a few spots where the script fails and it is on a frame or window switch or the first element after the switch.

Here is an example, where I have to dig down to a frame but I stuck a few times finding the first frame
(the “unable to verify image” error msg is a bit weird)

WebUI.switchToFrame(findTestObject(‘Object Repository/Moris/Frames/frontend_main’), GlobalVariable.$timeout)
WebUI.switchToFrame(findTestObject(‘Object Repository/Moris/Frames/frontend_maincontent’), GlobalVariable.$timeout)
WebUI.switchToFrame(findTestObject(‘Object Repository/Moris/Frames/data1’), GlobalVariable.$timeout)

the log says:
=============== ROOT CAUSE =====================
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/Moris/Frames/frontend_main’ located by ‘//*[@name = ‘frontend_main’]’ not found

For trouble shooting, please visit: https://docs.katalon.com/katalon-studio/docs/troubleshoot-common-execution-exceptions-web-test.html

08-07-2020 09:05:49 DE Test Cases/x_v0

Elapsed time: 51,139s

Test Cases/x_v0 FAILED.
com.kms.katalon.core.exception.StepFailedException: Unable to verify image ‘Object Repository/x/Frames/frontend_main’ present
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.stepFailed(WebUIKeywordMain.groovy:64)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:26)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToFrameKeyword.switchToFrame(SwitchToFrameKeyword.groovy:84)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToFrameKeyword.execute(SwitchToFrameKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:73)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.switchToFrame(WebUiBuiltInKeywords.groovy:2895)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$switchToFrame$3.call(Unknown Source)
at x_v0.run(Babavaro_ugylet_rogzites_v0:54)
at com.kms.katalon.core.main.ScriptEngine.run(ScriptEngine.java:194)
at com.kms.katalon.core.main.ScriptEngine.runScriptAsRawText(ScriptEngine.java:119)
at com.kms.katalon.core.main.TestCaseExecutor.runScript(TestCaseExecutor.java:339)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:330)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:309)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:301)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:235)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:114)
at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:105)
at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
at TempTestCase1596783946902.run(TempTestCase1596783946902.groovy:25)
Caused by: com.kms.katalon.core.webui.exception.WebElementNotFoundException: Web element with id: ‘Object Repository/x/Frames/frontend_main’ located by ‘//*[@name = ‘frontend_main’]’ not found
at com.kms.katalon.core.webui.common.WebUiCommonHelper.findWebElement(WebUiCommonHelper.java:1368)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToFrameKeyword$_switchToFrame_closure1.doCall(SwitchToFrameKeyword.groovy:77)
at com.kms.katalon.core.webui.keyword.builtin.SwitchToFrameKeyword$_switchToFrame_closure1.call(SwitchToFrameKeyword.groovy)
at com.kms.katalon.core.webui.keyword.internal.WebUIKeywordMain.runKeyword(WebUIKeywordMain.groovy:20)
… 17 more

here is the source:

what can I do to make this more stable?

thank you

You should tell the developers to improve their approach. That HTML is riven with non-standard HTML.

The frameset element is deprecated.

The frame element is deprecated.

Beyond that, then you have <iframe> elements inside deprecated frame/frameset structures. I’m confident your problem can be fixed but I don’t have the time to wade through the gotchas waiting in the code I haven’t seen. Maybe someone else does.

But seriously, tell the devs to drag themselves into the current decade, if not century.

Yeah, good point. I haven’t seen frameset and frames in decades. Unfortunatelly this is an enterprise legacy software which is still in production and will be for long time:
I’m on the edge of telling them that I refuse to automate this application due to the ancient technology it is made of.
But staying on the positive side, I hope somebody could inspire me with a small bit of advice.


I feel your pain.

You may not have to tell them you refuse… just tell them that to use a frameset/frame and THEN say “DOCTYPE html” (that’s an HTML 5x doctype) is laughable. Say, “To what standard do you want me to test this thing? Is it written down somewhere?” Because really, given a failure, how the hell are you meant to know what is “wrong”? And how can you say why it is failing? If you ask them to codify (write a spec) precisely how it works, then maybe, just maybe, you can live with it.

Good luck with that :wink:

But back to the problem…

Firstly, I don’t do xpath. Even so, that locator looks good to me - and since it sometimes works, is likely fine. But since we know you have a complex document (documents in documents using frames) it’s likely you have varying load times between them.

If I were you, I would dig in and find a way to ensure each sub-doc is loaded before hitting any child elements within the docs. If you were me, you’d do that with JavaScript and DOM APIs (css selectors). But that’s me. :blush:

1 Like