Micro Focus QTP (UFT) Forums
Adding Visual Relation id via script to new object - 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: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Adding Visual Relation id via script to new object (/Thread-Adding-Visual-Relation-id-via-script-to-new-object)



Adding Visual Relation id via script to new object - jcraig26 - 11-03-2012

Here is the scenario. I am using a random number to create an email. It will be in a list with a '+' next to it in a grid. All rows will have the '+' and then the email address in line to the right. I need to expand down the '+' to verify that an email was sent to the email address with the random number. Not only do I not know the email address because of the random number, it can be anywhere in the list - first, last, or anything in between. This means I can't rely on index.

My plan - Both of these items are WEBELEMENTS. I want to create the '+' WEBELEMENT and use the email as a Visual Relation identifier in the script.

I can create the object for the email no problem. I am having problems getting the visual relation added to the '+'. I may have been looking at this too long as well so sorry if it is a minor mistake I am overlooking. I need to remember to blink! :-)

Here the script - I set the email for testing:
Code:
Dim sEmail
Dim oDesc        'Description Object
Dim colObject    'Object Collection
sEmail="john214@smith.com"

Set oDesc = Description.Create
oDesc( "micclass" ).value = "WEBELEMENT"
'Additional property- for more focused and controlled collection
oDesc( "Innertext" ).value = sEmail

Set colObject = Browser("title:=MYTITLE").Page("title:=MYTITLE").ChildObjects(oDesc )


Dim oVisualRelation, oRelationToElement, oElementDesc,colobject2
Set oVisualRelation = VisualRelations.Create
Set oRelationToElement = oVisualRelation.Add
oRelationToElement.relatedobjectpath = "Browser(""title:=MYTITLE"").Page(""title:=MYTITLE"").ChildObjects(oDesc )"
oRelationToElement.relativeposition = micRelLeft
oRelationToElement.setargument micRelInline, True

Set ElementDesc = Description.Create
ElementDesc("micclass").Value = "WEBELEMENT"
ElementDesc("visual relations").Value = VisualRelation
Set colobject2 = Browser("title:=MYTITLE").Page("title:=MYTITLE").ChildObjects(ElementDesc)

colobject2(0).Highlight

------------------------------------------------------------------------

Sorry if this is a little simple for this forum. I am stuck and relatively new to QTP. Thanks in advance!

Okay, according to QTP's help files, you can't do this. You must have the object in the object repository to use it as a visual relation identifier.

New plan. Use existing object - add the WEBELEMENT for the email, but update the innertext value. This would make the object on the correct row.

Now, how do I update the object values via the script... back to research. But, any suggestions, please let me know.

Thanks!


RE: Adding Visual Relation id via script to new object - ourhari - 06-24-2013

Disclaimer: I understand this is a old thread, but thought that I can post a code snippet so that it can be referred.

In continuation with my another thread (https://www.learnqtp.com/forums/Thread-Visual-Relations-does-not-work-with-DP), I tried to implement the above "new plan", which worked perfect for me. I have used "setTOProperty" to set the property.

Here is the code.
Code:
Dim  desc1, desc2

Set desc1 = Browser("MyBrowser").Page("MyPage").WebElement("Country")
desc1.highlight
desc1.setTOProperty "innertext", "Date of Last Update:"
desc1.highlight


Dim VisualRel, relation
Set VisualRel = VisualRelations.Create

Set relation = VisualRel.Add
relation.RelatedObjectPath = "Browser(""MyBrowser"").Page(""MyPage"").WebElement(""Country"")"
relation.relativeposition = micRelLeft
relation.setargument micRelInline, True
Set relation = Nothing

Set desc2 =  Description.Create
desc2( "innertext").Value = ".*"
desc2("html tag").value= "TD"
desc2("Visual Relations").Value = VisualRel

Browser("title:=.*").Page("title:=.*").WebElement( desc2).highlight

NOTE: Care must be taken, as for the rest of the QTP execution session, "Country" object still refers to the "Date of Last Update:" label only. However, after the execution, the local repository is intact, and points to the Country label only.