Ask a Question

Return a page object using vbscript function and use it from another func

SOLVED
salley
Frequent Contributor

Return a page object using vbscript function and use it from another func

Hi , i'm trying to create a generic function, that will return an object then call that function to do specific task. my script is executing successfully when the object exists, but giving me run time error when the object is not there, pls see example below,,

thanks, any help will be appreciated

'+++++++

Function PoScreen
Set sPage=Aliases.browser.MainPage
'Selects Company
strEffDteProp=Array("ObjectIdentifier","ObjectType")
strEffDtePropVal=Array("DisplayEffectiveDate","Textbox")
Set objEffDte=MyObj (sPage,strEffDteProp,strEffDtePropVal)
objEffDte.SetText"11/01/2017"

End Function

 

 

'@@@@@@@@@@@@@@

Function MyObj(sPage,arrProp,arrVal)
Set obj=sPage.FindChild(arrProp,arrVal,50)
If (obj.Exists) Then
Set MyObj=obj
Else
Log.Message"Obj Not Found"
End If
End Function

 

''''''''this is error"

' TEST LOG

' Obj Not Found
Object required: 'myObj(...)' 
Script execution was interrupted. 

1 ACCEPTED SOLUTION

Accepted Solutions
AlexKaras
Community Hero

Re: Return a page object using vbscript function and use it from another func

Hi,

 

Observed behavior is correct and expected one.

When object is not found, the value returned by MyObj() is not an object. Thus it obviously does not contain the .SetText() method.

Suggested code modification:

Function PoScreen
Set sPage=Aliases.browser.MainPage
'Selects Company
strEffDteProp=Array("ObjectIdentifier","ObjectType")
strEffDtePropVal=Array("DisplayEffectiveDate","Textbox")
Set objEffDte=MyObj (sPage,strEffDteProp,strEffDtePropVal)
If (objEffDte.Exists) Then
  objEffDte.SetText"11/01/2017"
Else
  ... ' process appropriately
End If
End Function
 
 
'@@@@@@@@@@@@@@
Function MyObj(sPage,arrProp,arrVal)
' Set obj=sPage.FindChild(arrProp,arrVal,50)
' If (obj.Exists) Then
' Set MyObj=obj
' Else
' Log.Message"Obj Not Found"
' End If

Set MyObj=sPage.FindChild(arrProp,arrVal,50)
If (Not MyObj.Exists) Then
  Log.Message"Obj Not Found"
End If
End Function
 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

2 REPLIES 2
AlexKaras
Community Hero

Re: Return a page object using vbscript function and use it from another func

Hi,

 

Observed behavior is correct and expected one.

When object is not found, the value returned by MyObj() is not an object. Thus it obviously does not contain the .SetText() method.

Suggested code modification:

Function PoScreen
Set sPage=Aliases.browser.MainPage
'Selects Company
strEffDteProp=Array("ObjectIdentifier","ObjectType")
strEffDtePropVal=Array("DisplayEffectiveDate","Textbox")
Set objEffDte=MyObj (sPage,strEffDteProp,strEffDtePropVal)
If (objEffDte.Exists) Then
  objEffDte.SetText"11/01/2017"
Else
  ... ' process appropriately
End If
End Function
 
 
'@@@@@@@@@@@@@@
Function MyObj(sPage,arrProp,arrVal)
' Set obj=sPage.FindChild(arrProp,arrVal,50)
' If (obj.Exists) Then
' Set MyObj=obj
' Else
' Log.Message"Obj Not Found"
' End If

Set MyObj=sPage.FindChild(arrProp,arrVal,50)
If (Not MyObj.Exists) Then
  Log.Message"Obj Not Found"
End If
End Function
 

 

Regards,
  /Alex [Community Hero]
____
[Community Heroes] are not employed by SmartBear Software but
are just volunteers who have some experience with the tools by SmartBear Software
and a desire to help others. Posts made by [Community Heroes]
may differ from the official policies of SmartBear Software and should be treated
as the own private opinion of their authors and under no circumstances as an
official answer from SmartBear Software.
The [Community Hero] signature is used with permission by SmartBear Software.
https://community.smartbear.com/t5/custom/page/page-id/hall-of-fame
================================

View solution in original post

salley
Frequent Contributor

Re: Return a page object using vbscript function and use it from another func

Thank you so much,,,,,,,,,,,,,,,, got it, 

cancel
Showing results for 
Search instead for 
Did you mean: