我正在学习QTP。我遇到的一个问题是网页同步问题。我确实知道如何使用wait()序列以及Browser(“ Google”)。Page(“ Google”)。Sync。
但是必须有更好的方法来与页面同步。我希望QTP同时等待,我希望脚本在找到对象后立即继续。我不想更改QTP设置,因为它会减慢脚本速度。
你们能给我一个示例函数,最好使用for循环,这样我每次需要验证检查点时就可以调用该函数。
提前致谢
result = Browser("Google").Page("Google").Exist(20)
要么
result = Browser("Google").Page("Google").WebElement("xyz").Exist(20)
这将等待20秒钟,直到该页面或第二种情况下存在Web元素。一旦找到对象或超时,脚本将继续。
结果将包含true
或false
取决于对象是否存在
请注意,您可以在“测试设置”中找到的对象同步超时将添加到该.Exist(seconds)
超时中,除非您.Exist()
不使用类似以下参数的情况:
' Quick check-and-continue to see if an object does not exist:
' We expect the page to be existing, wait for it at least 10 second:
if Browser("Google").Page("Google").Exist(20) then
' Do a quick check that the warning div does not exist, note the parameter
' less usage of Exist()
if Browser("Google").Page("Google").WebElement("html id:=warningContainer").Exist() Then
MsgBox "There was a warning on the page!"
else
MsgBox "Everything is fine!"
end if
else
MsgBox "The page did not exist!"
end if
编辑:
您可以Exist
循环使用:
' Never ending loop until found:
Do Until Browser("Google").Page("Google").WebElement("xyz").Exist()
wait 1
Loop
' Or a loop with a timeout
timeout = 20
Do until (timeout = 0 OR Browser("Google").Page("Google").WebElement("xyz").Exist()
wait 1
timeout = timeout - 1
Next
我已经wait 1
故意实现了。您可以不这样做,但是以我的经验,它可能会产生不必要的随机副作用,例如永远不会加载的浏览器页面导致测试失败。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句