Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Is there any Sync function to AJAX frames?
#2
Solved: 11 Years, 3 Months, 3 Weeks ago
There are several ways to do dynamic waits for AJAX calls. It all depends on what is changing on the page. For example, sometimes an object exists on the page, but is just hidden, either by having coordinates off the visible area, or by having a height and width of 0, or by having the visible property set to false. Otherwise, objects can be inserted into the DOM via an AJAX call. All of these scenarios require different code. The following examples are registered functions so that they can be called on a WebElement directly. To illustrate waiting for a specific object to have a height and width greater than 0 (thereby making the object visible):

Code:
'@Description Waits until the test object has width and height greater than zero, pass Null for timeout to accept default of 10 seconds.
Public Sub WaitForVisibility(test_object, ByVal timeout)
    If IsEmpty(timeout) Or IsNull(timeout) Then timeout = 10 End If
    Dim start: start = Timer    
    Do While (test_object.GetROProperty("width") <= 0 And test_object.GetROProperty("height") <= 0) And (Timer - start < timeout)
        Wait 0, 500
        test_object.Init
    Loop
    Wait 0, 500
End Sub
RegisterUserFunc "WebElement", "WaitForVisibility", "WaitForVisibility"

To wait for the existence of an object:

Code:
'@Description Waits until the test object exists, pass Null for timeout to accept default of 10 seconds.
Public Sub WaitForExistence(test_object, ByVal timeout)
    If IsEmpty(timeout) Or IsNull(timeout) Then timeout = 10 End If
    Dim start: start = Timer    
    Do While (Not test_object.Exist(0)) And (Timer - start < timeout)
        Wait 0, 500
        test_object.Init
    Loop
    Wait 0, 500
End Sub
RegisterUserFunc "WebElement", "WaitForExistence", "WaitForExistence"
Reply


Messages In This Thread
RE: Is there any Sync function to AJAX frames? - by cdesserich - 09-08-2010, 01:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Calling a Function in Function Library when function is defined in an Action jitenderkkr 0 2,967 11-27-2014, 12:53 PM
Last Post: jitenderkkr
  Testing web Application that makes AJAX calls pendri 2 3,927 05-24-2011, 02:36 PM
Last Post: surya_7mar
  How can I fetch server time using function Now or any other function? blanchedsouza 2 5,104 11-07-2009, 08:34 PM
Last Post: Ankur
  Ajax calandar rajaselvan.d 0 1,807 05-08-2009, 01:36 PM
Last Post: rajaselvan.d

Forum Jump:


Users browsing this thread: 1 Guest(s)