Issue with `WebUI.findWebElements()` and Smart Locator

*Summary
I am encountering an issue when using WebUI.findWebElements() with a Smart Locator in Katalon Studio.

*Steps to reproduce
1. Use WebUI.openBrowser()to navigate towww.google.com. 2. Define a Smart Locator in the Object Repository targeting a div` element.
3. In a test case, use the following code:

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

TestObject myDivSmartLocator = findTestObject(‘Object Repository/myDivSmartLocator’)
WebUI.openBrowser(“https://www.google.com”)
List elements = WebUI.findWebElements(myDivSmartLocator, 10)
println “Number of elements found: ${elements.size()}”

*Expected Results
The code should find the correct number of div elements on the Google homepage that match the Smart Locator’s criteria.

*Actual Results
Only 1 element is being found, even though there might be more matching div elements on the page. (print log: Number of elements found: 1)

*Blocker?
Yes

*** Image


*Operating System
Windows 10

*Katalon Studio version
version 10.1.0

*Katalon Studio logs
Windows logs folder: Katalon Studio folder>\config\.metadata\.log

Environment (for Web Testing)
Chrome Version 134.0.6998.118 (Official Build) (64-bit)

1 Like

Hello there, welcome!

I have tried to reproduce this but in my case i received an “Unknown locator” message on the log.

I am not familiar enough with Smart Locators to help you more, but based on the message I received it could be related with using valid Smart Locator syntax. (Maybe “div” is not valid as a Smart Locators.

Anyway, using “div” as a way to locate multiple elements in an HTML could and on a 100+ list of elements. Did you try this to understand Multiple element finding or you really need to get that list of divs?

As a workaroung you can change the selection method and this should work fine:


I have tried the same code but using CSS as the selection method and it logged me 4 div elements.

Hope it helps, in the mean time.

1 Like

So, I ran your test case with a few modifications, as below, and got the result further down at the last bit. Like @gmarichal, I think you (or maybe the “Smart Locator”) did not make a proper pathway for your <div> objects and that is why you/it did not get a “proper” count.

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

TestObject myDivSmartLocator = com.Tools.makeTO('//div')    

WebUI.openBrowser("https://www.google.com")
WebUI.waitForPageLoad(10)
List<WebElement> elements = WebUI.findWebElements(myDivSmartLocator, 10)
println("Number of elements found: ${elements.size()}")

2025-03-27 09:15:42.877 DEBUG testcase.blah blah     - 5: println(Number of elements found: $elements.size())
Number of elements found: 156

Edit: @Elly_Tran Can you do an experiment with the above test case using your team and the “Smart Locator” option to see if there is an issue?

2 Likes

I wonder if anybody actually uses “Smart Locator”.
Maybe none uses it.
I could not find any documentation for it.
So I do not know “Smart Locator” at all.

Hello everyone,

The purpose of this ticket is to report an issue related to Smart Locators. When I use a Smart Locator to get all elements, it’s always returning only one, even though there are more.

Could you please double-check this issue with Smart Locators?

I’ve also created an example to show the difference between Smart Locator and CSS results.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject

import org.openqa.selenium.WebElement

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

def myDivSmartLocator = findTestObject('Object Repository/myDivSmartLocator')
def myDivCssLocator = findTestObject('Object Repository/myDivCssLocator')

WebUI.openBrowser("https://testautomationpractice.blogspot.com/")
WebUI.waitForPageLoad(30)
List<WebElement> smartElements = WebUI.findWebElements(myDivSmartLocator, 5)
println("Number of elements found by smart locator: ${smartElements.size()}")

List<WebElement> cssElements = WebUI.findWebElements(myDivCssLocator, 5)
println("Number of css elements found by css locator: ${cssElements.size()}")

Console log:
Number of elements found by smart locator: 1
Number of css elements found by css locator: 12

1 Like

I’ve hit the same snag too. The issue seems to come from trying to find a list of elements—it only returns the first one.
To make sure it supports both XPath and CSS properly in one place, you could try finding a single element using WebUI.findElement(testObject) as a quick test. That might help you better understand how it behaves.