Forum Discussion

DaveBillingham's avatar
DaveBillingham
New Contributor
4 years ago
Solved

Best way to dynamically iterate a set of repeating fields on a web page in Keyword Test

I'm developing a keyword test to property checkpoint some values on an Oracle Cloud web based application. The web form has two sections - header and details. The details section consists of one or more product item lines with product descriptions, quantities, prices, units of measure, the usual financial stuff.

 

I've created a data driven keyword test which successfully property checks the header values. I'm now trying to property check each of the item lines in a data driven loop.

 

The problem I'm hitting is that the individual fields are not arranged in any kind of table or grid as such. Instead they are all individual fields with dynamically generated at runtime with IDs such as:

ItemName1    QuantityX31   UoMX411
ItemName2    QuantityX32   UoMX412
ItemName3    QuantityX33   UoMX413

As far as I can see I have two choices:

* Create name mapping items for every possible field up to a maximum number of expected rows and use If...Exists to check the content if the field is available on the form

* Loop the data counting the row number, dynamically generate the field name using some kind of expression such as "ItemName" + RowNumber and then check the value

I've considered using name mapping wildcards such as ItemName* but that will not identify the field relating to my specific data loop.

My developer instincts say to use the second option but I have literally know idea how to actually implement it. Does anyone have any experience of this and could point me in the direction of an example or tutorial?

Update:
I've looked at Solved: Finding Elements on a Web Page - SmartBear Community which seems to partially solve my problem. However I can't use it directly because the web page I'm working with is not a fixed URL. It's actually the results of a "search" within the web app and so I can't issue a Browsers.Item(btChrome).Run() in the script.

Also ideally I'd like to keep the use of scripts to a minimum and, where scripts are needed, create a reusable script to return any textContent based on a "PageContent" and "XPath" pair of parameters.

  • function SearchFor(Page = Browser.currentPage, GridId)

    On Page

      Find container of the grid GridId

        On container, loop until row number

           Items[] = ItemName<Counter> + Quantity<key><Counter> + Uo<key><Counter>

    return Items

     

    Don"t using KWT but in script it's not too complex

3 Replies

  • BenoitB's avatar
    BenoitB
    Community Hero

    function SearchFor(Page = Browser.currentPage, GridId)

    On Page

      Find container of the grid GridId

        On container, loop until row number

           Items[] = ItemName<Counter> + Quantity<key><Counter> + Uo<key><Counter>

    return Items

     

    Don"t using KWT but in script it's not too complex

    • DaveBillingham's avatar
      DaveBillingham
      New Contributor

      Merci beaucoup Benoit, je suis nouveau avec TestComplete (et Francais!), je vais donc l'essayer plus tard.

      • sonya_m's avatar
        sonya_m
        SmartBear Alumni (Retired)

        Benoit, thank you for helping🙂

         

        DaveBillingham , did you have a chance to check if this works? Please share your experience with us!