Happy weekend to the reviewers :) I am stuck while I am trying to override a method in UFT
for objects like link
, Image
& button
. I get an unknown error during the execution of script.Would be helpful if someone can direct me. Below is my code
' Creating Browser description
' "title:=Work Transfer Management System - WTMS"
Set WTMSBrwsr = Description.Create
WTMSBrwsr("title").Value = "Work Transfer Management System - WTMS"
' Creating Page description
' "title:=Work Transfer Management System - WTMS"
Set WTMSPge = Description.Create
WTMSPge("title").Value = "Work Transfer Management System - WTMS"
'Creating link description
set OdescLnk= Description.Create
OdescLnk("Link").value="Engineering Work Placement"
OdescLnk("html tag").value="A"
Browser(WTMSBrwsr).Page(WTMSPge).Link(OdescLnk).fnBtnClick
'function Lib
RegisterUserFunc "WebButton", "fnBtnClick", "fnBtnClick"
RegisterUserFunc "Link", "fnBtnClick", "fnBtnClick"
RegisterUserFunc "Image", "fnBtnClick", "fnBtnClick"
'Function Definition
Function fnBtnClick(objControl)
'Check if object exists
If objControl.Exist Then
'Check if the object is enabled or not
If objControl.GetROProperty("disabled") <> 0 Then
'Click on the button
objControl.Click
End If
End If
End Function
The errors occurs at Browser(WTMSBrwsr).Page(WTMSPge).Link(OdescLnk).fnBtnClick
Could you please help me know if this is a write way to use a method?
The script, as every script, is executed from top to down.
When
Browser(WTMSBrwsr).Page(WTMSPge).Link(OdescLnk).fnBtnClick
is executed, it will look for a registration for that function, but that does not exist, because the code
RegisterUserFunc "WebButton", "fnBtnClick", "fnBtnClick"
RegisterUserFunc "Link", "fnBtnClick", "fnBtnClick"
RegisterUserFunc "Image", "fnBtnClick", "fnBtnClick"
has not yet been executed.
So move the RegisterUserFunc
calls up to the top, and it will work.
It might also improve the readability of the code if you declare the function before you reference its name in the RegisterUserFunc
calls, so better move the function definition to the top as well.