CS agents will respond to tickets via forum instead of private helpdesk to support other users with similar issues.

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!!

 

Comments

  • 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

     
  • Thanks. It worked.
  • Hi Could you provide the code for the above query I too is searching for same

Sign In or Register to comment.