# Unpredictable WebElementNotFoundException

**URL:** <https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264>\
**Category:** Web Testing\
**Tags:** katalon-studio\
**Created:** [August 7, 2020, 9:39am UTC](https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264 "2020-08-07T09:39:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![daniel.makra](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daniel.makra/32/18397_2.png) [@daniel.makra](https://forum.katalon.com/u/daniel.makra)\
**Post date:** [August 7, 2020, 9:39am UTC](https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264/1 "2020-08-07T09:39:36Z")

</div>

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.waitForPageLoad(GlobalVariable.$timeout)  
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](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.  
Reason:  
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:

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

what can I do to make this more stable?

thank you  
daniel

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 7, 2020, 11:34am UTC](https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264/2 "2020-08-07T11:34:24Z")

</div>

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

The **frameset** element is **[deprecated](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frameset)**.

The **frame** element is **[deprecated](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/frame)**.

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.

---

<div class="post-metadata">

**Author:** ![daniel.makra](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/daniel.makra/32/18397_2.png) [@daniel.makra](https://forum.katalon.com/u/daniel.makra)\
**Post date:** [August 7, 2020, 12:30pm UTC](https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264/3 "2020-08-07T12:30:31Z")

</div>

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.

thanks  
d

---

<div class="post-metadata">

**Author:** ![Russ\_Thomas](https://dub1.discourse-cdn.com/katalon/user_avatar/forum.katalon.com/russ_thomas/32/11884_2.png) [@Russ\_Thomas](https://forum.katalon.com/u/Russ_Thomas)\
**Post date:** [August 7, 2020, 1:12pm UTC](https://forum.katalon.com/t/unpredictable-webelementnotfoundexception/46264/4 "2020-08-07T13:12:55Z")

</div>

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 😉

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. 😊
