01-26-2011, 02:35 AM
I'm not sure what you are trying to accomplish here. You seem to be avoiding QTP native functions. I would code this something more like this:
If you are trying to create a reusable function for checking if the object exists and is enabled, you could create a separated function library and do something like the code below putting the ExistAndEnabled function in the separate library and associating it to your test. If it is defined in the test, the RegisterUserFunc statement must be executed before the function can be used:
I'm not sure if this is going to help you or not, but I hope it does.
Code:
With Browser("ActiTIME-Login").Page("ActiTIME-Login")
If .WebEdit("username").Exist() Then
If .WebEdit("username").GetROProperty("disabled") <> 1 And _
.WebEdit("username").GetROProperty("readonly") <> 1 Then
.WebEdit("username").Set "admin"
End If
End If
If .WebEdit("pwd").Exist() Then
If .WebEdit("pwd").GetROProperty("disabled") <> 1 And _
.WebEdit("pwd").GetROProperty("readonly") <> 1 Then
.WebEdit("pwd").Set "manager"
End If
End If
.WebButton("Login now").Click
End With
If you are trying to create a reusable function for checking if the object exists and is enabled, you could create a separated function library and do something like the code below putting the ExistAndEnabled function in the separate library and associating it to your test. If it is defined in the test, the RegisterUserFunc statement must be executed before the function can be used:
Code:
Function ExistsAndEnabled(test_object)
ExistsAndEnabled = False
If test_object.Exist(0) Then
If test_object.GetROProperty("disabled") <> 1 And test_object.GetROProperty("readonly") <> 1 Then
ExistsAndEnabled = True
End If
End If
End Function
RegisterUserFunc "WebEdit", "ExistsAndEnabled", "ExistsAndEnabled"
If Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("username").ExistsAndEnabled() Then
Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("username").Set "admin"
End If
If Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("pwd").ExistsAndEnabled() Then
Browser("ActiTIME-Login").Page("ActiTIME-Login").WebEdit("pwd").Set "manager"
End If
Browser("ActiTIME-Login").Page("ActiTIME-Login").WebButton("Login now").Click
I'm not sure if this is going to help you or not, but I hope it does.