Home > Web Automation Specific > Web Synchronization

Web Synchronization

WinTask simulates the user's interactions while browsing the Internet. When clicking a link to a new web page, the user typically waits for the page to load before attempting to do anything with the new page. If the user attempts to enter text into a field or click a link on the new page, unpredictable results may occur if the user fails to wait for the page to fully load. The user's actions are "Synchronized" with the web page.

WinTask reproduces this behavior through the use of several script statements that wait for the web page to load before passing control to the next script statement. These statements are inserted into the automation script generated during Recording mode. The most important of these statements is the UsePage statement that is generated each time the web page title changes.

The UsePage function waits for a web page with the specified title to be located and becomes ready for user input. During execution of the automation script, UsePage blocks until all elements on the specified page have been created and loaded with text. The script then continues applying user actions against the page. An error message is displayed if the page is not ready within the system specified timeout value as defined by the #ActionTimeout system variable. The default value of this system variable can be changed if a particular web page consistently takes longer than normal to load.

On some web pages, the page does not change significantly in response to the clicking of a link or completing data input on the page. If the target page exhibits this behavior, copying the UsePage statement will instruct WinTask to wait for the page to be updated before proceeding with additional user actions. In most cases, this will solve a web page synchronization problem.

The UsePage function can return if a web page title partially matches the text specified in the function call. This can lead to situations where user actions are attempted before the desired page has loaded. Setting the system variable #UsePageExact equal to 1 will modify the behavior of the UsePage function to remain blocked until a web page is loaded with a title that exactly matches the text in the function call.

Additional WinTask web synchronization functions:

Example code demonstrating Web Synchronization using IE browser

'Use Recording mode to launch URL www.wintask.com/demos
'Wait for page to load and click the "Multiple pages iteration" link
'Wait for page to load and click the "2" link
'Wait for page to load and click the "here" link

StartBrowser("IE","www.wintask.com/demos")

UsePage("WinTask Demonstration Pages")
    ClickHTMLElement("A[INNERTEXT= 'Multiple pages itera']")

UsePage("Page Iteration 1")
    ClickHTMLElement("A[INNERTEXT= '2']")
    ClickHTMLElement("A[INNERTEXT= 'here']")

In the code above, the StartBrowser function starts Internet Explorer and loads the www.wintask.com/demos URL. Once the page has finished loading, the first UsePage function waits until a page titled "WinTask Demonstration Pages" has loaded. In this example, the UsePage verifies the page title and returns. Execution passes to the ClickHTMLElement function. The ClickHTMLElement function then locates the element on the page and clicks the "Multiple pages iteration" link to load a new page. The ClickHTMLElement function in this example can click the link "2" to load the Page Iteration 2. There is no UsePage between the last 2 ClickHTMLElement lines, Recording Mode did not generate a new UsePage as both pages start with the same characters. To force a synchronization on the new page, add manually the correct UsePage:

UsePage("Page Iteration 1")
        ClickHTMLElement("A[INNERTEXT= '2']")

UsePage("Page Iteration 2")
        ClickHTMLElement("A[INNERTEXT= 'here']")

The second UsePage function just added waits for a page titled "Page Iteration 2" to load. However since the titles of both pages start with identical text ("Page Iteration "), the second UsePage function may return due to a "fuzzy" match against the first page if the second page does not fully load within the time specified by the #ActionTimeout system variable. The second ClickHTMLElement function may work correctly if both pages contain the same link.
In order to guarantee navigation to the desired web page, the second UsePage function must not return until the second page is completely loaded. The second UsePage function can be instructed to wait for a web page which exactly matches the specified title ("Page Iteration 2") by adding the #UsePageExact statement to the script as follows:

StartBrowser("IE", "www.wintask.com/demos")

#UsePageExact=1

UsePage("WinTask Demonstration Pages")
        ClickHTMLElement("A[INNERTEXT= 'Multiple pages itera']")

UsePage("Page Iteration 1")
        ClickHTMLElement("A[INNERTEXT= '2']")

UsePage("Page Iteration 2")
        ClickHTMLElement("A[INNERTEXT= 'here']")

 It should be noted that the placement of the #UsePageExact statement in the above example will force both UsePage functions to find an exact web page title match. Moving it in-between the first ClickHTMLElement function and the second UsePage function will allow a "fuzzy" match on the first UsePage function but require an exact match on the second.

Problems with Web Synchronization

If you still have trouble with your automation scripts after trying these web synchronization techniques, refer to article Web Advanced Synchronization for additional synchronization techniques.

See also

Introduction
Web Advanced Synchronization
HTML Descriptor
HTML Descriptor Advanced
How To Measure Response Time
Data Driven Automation