Search code examples
seleniumselenium-webdrivergroovykatalon-studio

Convert TestObject to List<WebElement> and pass it as arguments


I have a method and I want to pass a List as an argument but I suppose I need to pass TestObject in Katalon, so how do I convert that TestObject to List in Katalon


public void selectDropdown(List<WebElement> ele, String value) throws InterruptedException {
        for (int i = 0; i < ele.size(); i++) {

            String option = ele.get(i).getText();
            if (option.contains(value)) {

                ele.get(i).click();
                break;
            }
            Thread.sleep(500);
        }
        Thread.sleep(500);
    }

So I think I need to pass TestObject in place of List but how do I then convert that test object in to a List


Solution

  • This is how I eventually did it.

    @Keyword
    def selectDropdown(TestObject Obj, String Value)
    {
       List<WebElement> ele = WebUiCommonHelper.findWebElements(Obj, 20);
    
       for (int i = 0; i < ele.size(); i++) 
       {
           String option = ele.get(i).getText();
           if (option.contains(value)) 
           {
              ele.get(i).click();
              break;
           }
           Thread.sleep(500);
       }
       Thread.sleep(500);
    }