QTP 自动化测试 之 Object.Exist()不起作用怎么办?

本文介绍了一种通过检查网页元素的可见状态来判断其是否存在的方法。利用DOM属性currentStyle.visibility获取元素可见性,结合Object.Exist方法进行综合判断。适用于隐藏元素的检测场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

有些对象用Object.Exist不起作用,因为是隐藏起来的所以用Object.Exist都是true

所以采用DOM里的currentStyle获取visibility来判断对象是否存在

1. update Obj_Exist(WaitSec)

2. Update OBJ_NOTExist

'------------------------------------------------------------------------------------------------------------------------
'Function         Obj_Exist
'Description      Obj_Exist
'Input            WaitTime
'Output           Obj_Exist
'------------------------------------------------------------------------------------------------------------------------
Function Obj_Exist(Parameter,Object)
On Error Resume Next
Err.Clear
visibleValue = Ucase(Cstr(Object.currentStyle.visibility)) 'Get the visibility value of the object
' Check if the object is not hidden and exist in <30> seconds.
StartTime = Time() 
Do while visibleValue = "HIDDEN"
Wait(1)
visibleValue = Ucase(Cstr(Action_Object.Object.currentStyle.visibility))
FindObjectResult = Eval(Object & ".Exist(1)")
If FindObjectResult and visibleValue<>"HIDDEN" Then
  Exit Do
End If
If CalculateTimeDuration(StartTime)>CInt(30) Then
Obj_Exist = "Error|" & FormatCurrentTime() & " Object not exist in " & WaitSec  & " seconds. Error Number: "&Err.Number&" Error Description: "&Err.Description&"|"
Exit Function
End If
Loop
' Check if the object is not hidden and exist in <WaitSec> seconds.


If Err.Number = 0  Then
  Obj_Exist = "Pass|" & FormatCurrentTime() & " Object is found successfully and visible.|"
Else 
  Obj_Exist = "Error|" & FormatCurrentTime() & " Unexpected Error occurred. Error: "&Err.Number&" Error Description: "&Err.Description&"|"
End If
End Function








'------------------------------------------------------------------------------------------------------------------------
'Function            Check_OBJnotExist
'Description       Check OBJnotExist
'Input                  Object string
'Output               Check result
'------------------------------------------------------------------------------------------------------------------------
Function OBJ_NotExist(Parameter,Object)
On Error Resume Next
Err.Clear
FindObjectResult = False
FindObjectResult = Eval(Object&".Exist(1)")
If Err.Number <> 0 Then
OBJ_NotExist = "Failed|"&FormatCurrentTime()&" Unexpected error while FindObject. Error details: "&Err.description&"|"
Else
If FindObjectResult and UCase(Cstr(Action_Object.Object.currentStyle.visibility))<>"HIDDEN" Then
OBJ_NotExist = "Failed|" &FormatCurrentTime()&" Object still exists.|"
Else
  OBJ_NotExist = "Pass|" &FormatCurrentTime()&" Object doesn't exist .|"
End If
End If
End Function


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值