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

Issue

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);
}

Answered By – enthusiasticCoder

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published