How to pass the element in object repository to find elements code

Can someone please help me on how to pass the element from the object repository to the find elements code that am using in my custom keyword. I want to pass the element locator as an argument so I can reuse it… Here is my code

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

WebDriver driver = DriverFactory.getWebDriver()

driver.findElements(By.id("elementid"))

 

I want to send the test object from object repository in place of “elementid” in the above line… Please help!!

 

Thanks. It worked.

Hi Could you provide the code for the above query I too is searching for same

Hi there,

You have two ways to do this:

  1. Use ‘findElements’ from WebUiCommonHelper class and pass in the test object from Object Repository:WebUiCommonHelper.findWebElements(findTestObject('Object Repository/Page_AppointmentConfirmation/lbl_Comment'), 30)

  2. Get test object from Object Repository:

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

TestObject to = findTestObject('Object Repository/Page_AppointmentConfirmation/lbl_Comment')

WebDriver driver = DriverFactory.getWebDriver()

driver.findElements(By.id(to.findPropertyValue('id')))

This API doc will have all the APIs you need: http://api-docs.katalon.com/studio/v4.5.0/api/com.kms.katalon.core/com/kms/katalon/core/testobject/TestObject.html

Thanks

Vinh Nguyen said:

Hi there,

You have two ways to do this:

  1. Use ‘findElements’ from WebUiCommonHelper class and pass in the test object from Object Repository:WebUiCommonHelper.findWebElements(findTestObject('Object Repository/Page_AppointmentConfirmation/lbl_Comment'), 30)

  2. Get test object from Object Repository:

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement

TestObject to = findTestObject('Object Repository/Page_AppointmentConfirmation/lbl_Comment')

WebDriver driver = DriverFactory.getWebDriver()

driver.findElements(By.id(to.findPropertyValue('id')))

This API doc will have all the APIs you need: http://api-docs.katalon.com/studio/v4.5.0/api/com.kms.katalon.core/com/kms/katalon/core/testobject/TestObject.html

Thanks

Hi

I just wanted to know if there is a way to store a list of objects using something like “findTestObjects” instead of just one at a time? I am just trying to avoid declaring one testobject variable for each object and instead use an arraylist. Thanks to let me know if that is a possibility

I think you’ve discovered (like me) that the Test Objects and the Repository don’t scale all that well…

Perhaps you’d benefit from writing your own Test Objects, live, in memory, and stop dealing with the OR. If so, you might find this discussion helpful: