Micro Focus QTP (UFT) Forums
Can i Give Variable in Object name ??? - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: Can i Give Variable in Object name ??? (/Thread-Can-i-Give-Variable-in-Object-name)



Can i Give Variable in Object name ??? - thiyaga - 06-18-2012

Hi All,

I have to iterate the following code.

Code:
Browser("Browser").Page("User").Frame("actionIFrame").WebButton("WebButton_2").Click
        Wait(3)
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$").Set BusinessName
        wait(2)
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_2").Set EmpCount
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_3").Set VolNumber
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_4").Set LegStrctr
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_5").Set BAddLine1
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_6").Set BAddLine2
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_7").Set BStreetName
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_8").Set BCityID
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_9").Set BCityName
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_10").Set BStateName
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_11").Set BCountryCd
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_12").Set PostalCd
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_13").Set BAddType
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_14").Set  BWorkNumber
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_15").Set BHomeNumber
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_16").Set BCellNumber
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_17").Set BEmail1
        Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$l1$_18").Set BEmail2
        wait(1)
        Browser("Browser").Page("User").Frame("actionIFrame").WebButton("WebButton_3").Click
        Wait(3)
        Browser("Browser").Page("User").Frame("actionIFrame").WebList("$PpyWorkPage$pBusinessList$l1$").Select 1

that is i have to click a
Code:
button([color=#FF0000]Browser("Browser").Page("User").Frame("actionIFrame").WebButton("WebButton_2").Click[/color])
each time, then a new frame will be created with same fields in the old frame. so the object name of new ly created fileds will be like

Code:
Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$[b]l2[/b]$").Set BusinessName

instead of

Code:
Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("$PpyWorkPage$pBusinessList$[b]l1[/b]$").Set BusinessName.

so in iteration how can i change the Name if the Object.That is i need Syntax for giving variable in object name.


RE: Can i Give Variable in Object name ??? - Ankesh - 06-18-2012

Try this
Code:
strObjectName="$PpyWorkPage$pBusinessList$"&[b]<enter dynamic value
which is changing, here l2>[/b]&"$"
Code:
Browser("Browser").Page("User").Frame("actionIFrame").WebEdit("name:="&strObjectName).Click

Regards,
Ankesh


RE: Can i Give Variable in Object name ??? - Surya - 06-20-2012

Hi,

If you are saving all the objects in OR, then you can iterate your code for all the frames by giving variable in your object name.

Regards,
Surya