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

Is there a way to loop through 2D List of WebElements?

edited October 3 in Web Testing

I was trying to figure out how to click on a div specified by the text of one
of it's child's inner text.

public class GetChildNodeFromList {
@Keyword
def GetChildNode(TestObject to, int i) {
ListWebElements users = WebUiBuiltInKeywords.findWebElements(to, 30)
//println users
for (user in users) {
println user
ListWebElements children = WebUiBuiltInKeywords.findWebElements(TestObject user, 30)
//println children
}

}

}

the problem is that you I couldn't get the children of user in users. is there a way to do that?

Thanks

Tagged:

Comments

  • edited October 4

    Hi Mark,
    The root caused is a user is a WebElement, not a Katalon TestObject
    To get children of a user, please try

    import com.kms.katalon.core.webui.common.WebUiCommonHelper
    List<WebElement> children = user.findElements(WebUiCommonHelper.buildLocator(put your children testobject here));
  • edited October 15

    I've figured out how to do that

    `public class GetChildNodeFromList {
    @Keyword
    def GetChildNode(TestObject to, String role) {
    List<WebElement> users = WebUiBuiltInKeywords.findWebElements(to, 30)

        //print users[0].getProperties()["text"]
    
        for (user in users) {
            if (user.getProperties()["text"].split()[1] == role) {
                user.click()
                break
            }
        }
    
    }
    

    }`

Sign In or Register to comment.