Forum Discussion

coopernico46's avatar
coopernico46
Occasional Contributor
7 years ago

How to extract a value from a label if the label is repeated

Hi all   I'm newbie with SOAP but i'm trying to do my best with my very first TestSet automation.   At the moment (most of the test case is done) i have only one issue, i don't know how to look i...
  • JHunt's avatar
    7 years ago

    As stated, using find you will only get the first result, so no issues with multiple results. The alternative would be findAll.

     

    To solve the error you just need to make sure the result for categoryCode is a String by getting the text(). Same thing as the line above it.

     

    String categoryCode = new XmlSlurper().parseText(context.response)
    .CategoryOption
    .find {it.PriceInfos.PriceInfo.find { it.'@BreakdownType'.text() == "02 A" }}
    .'@PricedCategoryCode'.text()
    context.testCase.setPropertyValue('CategoryList', categoryCode)

    Sorry I missed this before.

  • nmrao's avatar
    nmrao
    7 years ago

    coopernico46,
    See demo script. (use "log.info" instead of println)

    https://ideone.com/GIA7pN

     

    See the colored text (changes)

    def categoryCode = new XmlSlurper().parseText(context.response).'**'.find{ 
        it.PriceInfos.PriceInfo.find {
            it.'@BreakdownType'.text() == "02 A"
        }
    }.@PricedCategoryCode?.text()
    context.testCase.setPropertyValue('PricedCategoryCode', categoryCode)