[WebUI] Find Web Elements


This is a companion discussion topic for the original entry at https://docs.katalon.com/katalon-studio/docs/webui-find-web-elements.html

I wrote the following test case script:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI

WebUI.openBrowser('')

WebUI.navigateToUrl('https://katalon-demo-cura.herokuapp.com/')

TestObject tObj = findTestObject('Object Repository/Page_CURA Healthcare Service/a_Make Appointment')

List<WebElement> webelements = WebUI.findWebElements(tObj, 10)

WebUI.closeBrowser()

When I ran this, I got the following error:

2021-11-08 17:34:56.255 INFO  c.k.katalon.core.main.TestCaseExecutor   - --------------------
2021-11-08 17:34:56.260 INFO  c.k.katalon.core.main.TestCaseExecutor   - START Test Cases/New Test Case
2021-11-08 17:34:57.170 ERROR c.k.katalon.core.main.TestCaseExecutor   - ❌ Test Cases/New Test Case FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/Users/kazuakiurayama/katalon-workspace/healthcare-tests/Scripts/New%20Test%20Case/Script1636360141354.groovy: 11: unable to resolve class WebElement 
 @ line 11, column 6.
   List<WebElement> webelements = WebUI.findWebElements(tObj, 10)
        ^

1 error

	at com.kms.katalon.core.main.ScriptEngine.getScript(ScriptEngine.java:199)
	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:430)
	at com.kms.katalon.core.main.TestCaseExecutor.doExecute(TestCaseExecutor.java:421)
	at com.kms.katalon.core.main.TestCaseExecutor.processExecutionPhase(TestCaseExecutor.java:400)
	at com.kms.katalon.core.main.TestCaseExecutor.accessMainPhase(TestCaseExecutor.java:392)
	at com.kms.katalon.core.main.TestCaseExecutor.execute(TestCaseExecutor.java:273)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:142)
	at com.kms.katalon.core.main.TestCaseMain.runTestCase(TestCaseMain.java:133)
	at com.kms.katalon.core.main.TestCaseMain$runTestCase$0.call(Unknown Source)
	at TempTestCase1636360490755.run(TempTestCase1636360490755.groovy:25)

2021-11-08 17:34:57.227 INFO  c.k.katalon.core.main.TestCaseExecutor   - END Test Cases/New Test Case

How can I fix this error?

Ans:

I needed to add the following import statement.

import org.openqa.selenium.WebElement

The document says:

Returns

The found web elements or null if cannot find any.

I think this sentence is ambiguous. The word “web element” is not defined here.

Why not the document explicitly says that the keyword returns a List of org.openqa.selenum.WebElement object?

Many of the Katalon Studio users aren’t skilled enough for Java programming, and they are not aware that that they are supposed to write the required import statements for themselves.

The document should explicitly explain that users have to write the required import statement. Otherwise they would keep on posting in this User Forum asking how to fix the errors like this.

2 Likes