XPATH to array of TestObject

Hello,

does anyone know how I can use an XPATH expression to create multiple TestObjects?
Similar to the example below, but for each result node one TestObject:

TestObject testObject = new TestObject(‘test’);

testObject.addProperty(‘xpath’, ConditionType.EQUALS, ‘//div’, true);

Regards,
Aleksander

Maybe in a for loop?

Something like this. First you write a method for creation of a new ‘live’ object (courtesy of @Russ Thomas):

static TestObject makeTO(String xpath) {
    TestObject to = new TestObject()
    to.addProperty("xpath", ConditionType.EQUALS, xpath)
    return to
}

Then you call that function inside of your loop (tweek this as needed):

def TOlist =[]
for (i=0; i<10; i++){
    TOlist[i] = makeTO('//div['+i+']')
}
1 Like