HP UFT 中的 TypeOf 实现 vba
TypeOf implementation in HP UFT vba
正在寻找 HP-UFT VB实现类似于 VB TypeOf 或 Java instanceOf (Java)
的代码
一个例子:我的存储库中有一个对象有一个 Class "WebEdit" 我想写一个子过程来对它执行一个操作,但首先我想检查一下提供的对象是一个 webedit
例如这里是我想要的子程序
setIfNotBlank(
Browser("Google").Page("Search").WebEdit("SearchText")
, "Cute kities who actually rule the world" )
Sub setIfNotBlank( object , val )
if not ( object TypeOf WebEdit)
exit sub 'only proceed if WebEdit object
End if
object.set val
End Sub
根据传递的参数,我假设您已经将该对象添加到您的对象存储库中。将您的子重写为:
Sub setIfNotBlank( object , val )
If IsObject(object) then 'First checking if the parameter "object" is actually an object
If strComp(object.getToProperty("Class Name"),"WebEdit",1)=0 then 'Checking the value of its property "class Name". It should be "WebEdit"
object.Set val
Else
Exit Sub 'If "object" is not of type "WebEdit", then Exit Sub
Else
Exit Sub 'If parameter "object" is not an object, Exit Sub
End If
End Sub
正在寻找 HP-UFT VB实现类似于 VB TypeOf 或 Java instanceOf (Java)
的代码一个例子:我的存储库中有一个对象有一个 Class "WebEdit" 我想写一个子过程来对它执行一个操作,但首先我想检查一下提供的对象是一个 webedit
例如这里是我想要的子程序
setIfNotBlank(
Browser("Google").Page("Search").WebEdit("SearchText")
, "Cute kities who actually rule the world" )
Sub setIfNotBlank( object , val )
if not ( object TypeOf WebEdit)
exit sub 'only proceed if WebEdit object
End if
object.set val
End Sub
根据传递的参数,我假设您已经将该对象添加到您的对象存储库中。将您的子重写为:
Sub setIfNotBlank( object , val )
If IsObject(object) then 'First checking if the parameter "object" is actually an object
If strComp(object.getToProperty("Class Name"),"WebEdit",1)=0 then 'Checking the value of its property "class Name". It should be "WebEdit"
object.Set val
Else
Exit Sub 'If "object" is not of type "WebEdit", then Exit Sub
Else
Exit Sub 'If parameter "object" is not an object, Exit Sub
End If
End Sub