Get object properties of multiple objects using findTestObject for 1 object

Hi -

I have a case where want to compare some data (in a csv) file to some values on my AUT. The AUT has the values I want to compare to in individual objects on the screen (hyperlinks). The objects containing the values are identical, except they have different text and id values. So I have stripped down my object to find it only by class. When I verify and highlight, it finds the object 2 times, which is great.

What I want to do it to loop through each object (containing the text I want to verify) and compare against my .csv file. And I’d like to keep this code as a custom keyword to later compare in other places, where the number of objects I am comparing may be more, or fewer.

So I need a way to dynamically get the id or text of EACH of the target objects on screen, using the single object. So far, I have only been able to get the id or text of the first object of the 2 it finds.

So far, I have created a loop to get the text of the objects on the screen and compare to my .csv. The findTesObject method finds 2 objects. Great. But it only gets the text of the first object. The loop does not continue and findText again on the second.

Any ideas?

That’s a lot of text to digest a spec from. It would be a lot easier if you’d post some brief HTML which would help remove the chances of ambiguity.

Following is my best guess as to what you’re facing…

<a class="my_class" id="a" href="somelink">Somelink</a>
<a class="my_class" id="b" href="somelink2">Somelink2</a>
<a class="my_class" id="c" href="somelink3">Somelink3</a>
<a class="my_class" id="d" href="somelink4">Somelink4</a>

where, the only common thing is the use of A tags and the same class.

And, if I’m correct, you want a list of those ids, a,b,c, and d?

You want something like this, possibly.

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObjectimport org.openqa.selenium.WebElementimport com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUIWebUI.openBrowser('')WebUI.navigateToUrl(URL of your AUT)List<WebElement> anchors = WebUI.findWebElements(findTestObject('Object Repository/your test object name'), 10)for (WebElement anchor : anchors) {	String idStr = anchor.getAttribute("id")	WebUI.comment(">>> id is ${idStr}")}WebUI.closeBrowser()