Verify text present causes "NoSuchElementException"

Hi all :slight_smile:
I have test cases in which I need to verify text present on the page.
They all worked in the past, but now for some reason some of them are failed, and I get this error:

com.kms.katalon.core.exception.StepFailedException: Unable to verify text ‘הרשימות שלי’ is 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.VerifyTextPresentKeyword.verifyTextPresent(VerifyTextPresentKeyword.groovy:83)
at com.kms.katalon.core.webui.keyword.builtin.VerifyTextPresentKeyword.execute(VerifyTextPresentKeyword.groovy:68)
at com.kms.katalon.core.keyword.internal.KeywordExecutor.executeKeywordForPlatform(KeywordExecutor.groovy:60)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.verifyTextPresent(WebUiBuiltInKeywords.groovy:1693)
at com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords$verifyTextPresent$2.call(Unknown Source)
at All clicks on navbar.run(All clicks on navbar:25)
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:337)
at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:328)
at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:307)
at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:299)
at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:233)
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 TempTestCase1589273069182.run(TempTestCase1589273069182.groovy:23)
Caused by: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“css selector”,“selector”:“body”}
(Session info: chrome=81.0.4044.138)
For documentation on this error, please visit: Exceptions | Selenium

This is the test case - the next “verify text present” is working fine:

WebUI.click(findTestObject(‘All click on navbar/Page_/obj_my zone navbar prod’))

WebUI.verifyTextPresent(‘הרשימות שלי’, false)

WebUI.click(findTestObject(‘All click on navbar/Page_/obj_learn english navbar dropdown’))

WebUI.click(findTestObject(‘All click on navbar/Page_/obj_vocab game navbar prod’))

WebUI.click(findTestObject(‘All click on navbar/Page_/obj_level choose foundation prod’))

WebUI.verifyTextPresent(‘אוצר מילים’, false)

It worked in the past, I think it started giving this error when my chrome was updated to version 81 (I downloaded the required chromedriver). As mentioned, it doesn’t happen in all the “verify text present” cases, and it happens in ones that were working in the past.

Thanks!

Just to test your theory that it’s Chrome at fault… what happens when you run it against Firefox?

Have you tried adding wait before verify text present. It could be that the page is not loaded completely.

A post was split to a new topic: JavaScript error: this.each is not a function

Thanks! I added it and it’s working now :slight_smile:

A post was merged into an existing topic: JavaScript error: this.each is not a function

I tried Firefox now and it worked there…
I tried adding “wait for page load” as @vtanguturi suggested and it helped

2 Likes

Good that the wait worked. You can also use explicit waits before you proceed with other actions. Can you select my post as the solution for you issue it might help others too.
Thanks

This exception is thrown by various accessor methods to indicate that the element being requested does not exist . The next() method in Java returns the next element in the iteration or NoSuchElementException if the iteration has no more elements. The solution to this​ exception is to check whether the next position of an iterable is filled or empty. You should only move to this position if the check returns that the position is not empty. The following methods are used to check the next position:

  • hasNext()
  • hasMoreElements()