result = Browser("Google").Page("Google").Exist(20)
or
result = Browser("Google").Page("Google").WebElement("xyz").Exist(20)
This waits 20 seconds until the page, or in the second case an webelement exists. The script will continue as soon as the object is found or the timeout is passed.
Result will contain true
or false
depending if the object exists
Please note that the object synchronization timeout you can find in your Test Settings is added to the .Exist(seconds)
timeout except when you use .Exist()
without a parameter like:
' 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
EDIT:
You can use Exist
in a loop:
' 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
I've implemented the wait 1
on purpose. You can do it without, but in my experience that can create unwanted random side effect like a browser page that never gets loaded causing your test to fail.