Forum Discussion

mesg2anil's avatar
mesg2anil
Regular Contributor
14 years ago

How to modify the object names in the VB script during execution

Hi,



While executing the VB script in TC, when I insert a new row in the web application, below will be the path and the object...

Sys.Process("iexplore").Page("http://server/Default.asp").document.frames.Frame("mainFrame").document.all.Item("gdvDepositDetails_ctl02_ddlDepositType")

Sys.Process("iexplore").Page("http://server/Default.asp").document.frames.Frame("mainFrame").document.all.Item("gdvDepositDetails_ctl02_ddlDepositRefundable")



after entering the data in the above objects in the application, I click to add one more new row, object name will change a little as below...

Item("gdvDepositDetails_ctl03_ddlDepositType")          'only thing changes here is numeric digit 3, above in the first row object name it is 2

Item("gdvDepositDetails_ctl03_ddlDepositRefundable")



In the first row, the object name contains ct102 and second row will be ctl03, similarly number keep increasing as I add more rows... So, in this situation, if I want to use IF condition or FOR loop to input the data without mentioning object name and just change the numeric digit, how can I change ctl02 to ctl03 and input the data into the object in the application?



I might add just 1 row or sometimes I might add 4 or sometimes 10 rows, so for that reason it will be difficult to know how many rows I'm going to add as it depends on the data I need to input. How to handle this kind of situation in TC??

1 Reply

  • Hi,


    You can use the FindAllChildren method to search for all added items and then perform the same actions over each item in a loop. For example, you can use the following code:




    Set w = Sys.Process("iexplore").Page("http://server/Default.asp").document.frames.Frame("mainFrame").document.all

    Set items = w.FindAllChildren("idStr","gdvDepositDetails_*_ddlDepositType")

    If UBound(items) >= 0 Then

        For i = 0 To UBound(items)

           ' Perform needed actions

        Next

    Else

        Log.Warning("No items found.")

    End If


    To match dynamic characters in the idStr property value, you can use the asterisk (*) wildcard. For more information, please read http://smartbear.com/support/viewarticle/18943/.