Troubleshooting Script Playback Errors
Occasionally a web automation script you've just recorded fails when it's played back. Instead of the script running to completion, you are greeted with an error message and the script terminating abruptly. By carefully inspecting the error message and noting which statement generated the error, you can take corrective action to avoid the error condition. The following sections provide some guidance in helping you overcome run-time errors.
StartBrowser Errors
Most Web automation scripts start with the StartBrowser statement. The function starts Internet Explorer, loads the specified URL, and waits for the web page to load. If the web page fails to load within the default timeout period of 30 seconds, the function will fail.
If the web page normally loads but sometimes fails during times of heavy network traffic, the default timeout variable can be increased via the #ActionTimeout system variable. The #ActionTimeout variable can be increased just before the StartBrowser function and then restored to it's original value immediately following it.
The web page may fail to load because another window, possibly a pop-up, is preventing it. In this case, the Shell statement can be used in place of the StartBrowser statement. Help topic Page Timeout Error Message describes a solution where a security window must be dismissed before the desired web page can be loaded.
Another cause of failure is that the URL is temporarily unavailable. If you believe that the web page will be back online shortly, a function can be written that makes several attempts to load the URL before reporting an error. The script "Start browser and retry the url if unsuccessfull.src" provides an example of how one can be written. The script is located in the WinTask installation sub-directory "Advanced_Script_Examples".
UsePage Errors
The UsePage statement provides synchronization within the script, temporarily blocking script execution until the web page is completely loaded. If all of the elements on the specified page cannot be created and loaded with text within the default timeout period of 30 seconds, the function will fail.
If the web page fails to load within the default timeout period, the amount of time can be increased via the #ActionTimeout system variable. The #ActionTimeout variable can be increased just before the UsePage function and then restored to it's original value immediately following it.
The default behavior of the UsePage function is to allow the script to continue execution as soon as the web page finishes loading and the first character of a the page title matches the first character of the title specified in the UsePage function. At times this can lead to a false positive allowing the script to continue too early and then failing on a succeeding script statement. This situation can be remedied by setting the #UsePageExact system variable to 1 before the UsePage function. The UsePage function will now wait for a web page to be loaded with the fully specified page title, or fails immediately if the title of the loaded web page starts to deviate from the specified title.
The complement to the exact matching behavior invoked by setting the #UsePageExact system variable to 1 is to use "wildcards" in the UsePage statement. Wildcard behavior is invoked by truncating characters from the end of the web page title. This can be useful if the end of the web page title can vary each time the script is executed.
Some examples:
The UsePage statement in the following code will succeed as long as the title of the loaded web page begins with the letter "W". (Fuzzy match on "W").
' Wait for the WinTask home web page to be loaded.
UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
The UsePage statement in the following code will fail if the title of the loaded web page begins with "WinTasks". ("WinTasks" mismatches "WinTask - Auto")
' Require the web page title to exactly match the UsePage parameter.
#UsePageExact=1
UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
The UsePage statement in the following code uses wildcards to successfully match on any web page title that begins with "WinTask". The presence of the #UsePageExact system variable will not cause UsePage to fail unless the title deviates from "WinTask" in the first seven characters.
' Require the web page title to start with "WinTask" but allow any
' text to follow it.
#UsePageExact=1
UsePage("WinTask")
HTML Element Not Found Errors
This error can occur when the script attempts to interact with an element on the web page. OverHTMLElement, ClickHTMLElement, CaptureHTML, and WriteHTML are just some of the functions which may exhibit this error.
There are two causes for this error. The first is a synchronization error where the HTML element referenced in the function is not on the web page. The second situation is when the referenced HTML element is on the web page, but has a different HTML Descriptor than when the script was originally recorded.
Use the following step-by-step instructions to help diagnose and correct the problem.
Execute the script in question.
When the script fails and displays the error message, click the OK button to dismiss the message box. Leave Internet Explorer open on the web page.
If it appears that the web page hasn't fully loaded, or the wrong web page is being displayed, you may have a synchronization error. See the section titled UsePage Errors above and follow it's recommendations. Continue with the next step if the problem persists.
If the correct web page is displayed and has been fully loaded, there may be a problem with the HTML Descriptor. Bring up the WinTask editor and create a new script.
Start Recording Mode. Select the Nothing radio button on the Start Recording Mode dialog box and click the OK button.
Return to Internet Explorer and manually execute the steps on the web page that the script was attempting to automate.
Stop Recording Mode. Your actions will be inserted into the new WinTask script. Restore the web page in Internet Explorer to the state it was at when the failure occurred.
Save the newly recorded script. Compile and execute the script.
If the new script replays correctly, compare the newly generated HTML Descriptor with the corresponding one in the script with the error. If the HTML Descriptors are identical, a synchronization error is the likely cause. See the section titled UsePage Errors above and follow it's recommendations.
If the HTML Descriptor in the new script differs from the original script, update the original script so the HTML Descriptor matches the new script. Recompile and execute the script.
If the script still fails after trying all of the above recommendations, please contact us at info@wintask.com for further assistance.
Inaccurate click location by ClickElement
At times you may come across an error message generated by a WinTask function that failed because a preceding ClickHTMLElement statement did not execute correctly. As you watch the script execute, you see the mouse cursor click somewhere on the web page, but not on the intended element.
One possible cause for this error is that the script was attempting to click a small hyperlink but the default mouse click coordinates are inaccurate. The solution is to use the optional parameters of the ClickHTMLElement statement to pinpoint the mouse click coordinates.
Click slightly to the right and down from the top-left corner of the HTML element.
ClickHTMLElement("A[INNERTEXT= 'Top 10 Uses']",left,5,5)
Another cause for this error is that the HTML Descriptor specified in the ClickHTMLElement statement clicks an unintended element. This is usually caused by two or more elements on the web page that produce the same HTML Descriptor during recording mode. The solution is to use the Spy and Content Validation tools during recording mode to verify that the desired element is fully described by the generated HTML Descriptor. Use the techniques described in the section titled HTML Element Not Found Errors and the tools to identify the desired element.
Using Navigate instead of ClickHTMLElement
An alternative to correcting troublesome ClickHTMElement statements is the use of the Navigate statement to go directly to another web page. The Navigate statement provides synchronization by waiting for the target web page to load.
The following code illustrates how a ClickHTMElement statement can be replaced with a Navigate statement.
Original code generated during Recording Mode.
StartBrowser("IE", "www.wintask.com")
UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
ClickHTMLElement("A[INNERTEXT= 'How It Works']")
UsePage("WinTask - How it works")
ClickHTMLElement("A[INNERTEXT= 'Contact Us']")
Code modified to use the Navigate function.
StartBrowser("IE", "www.wintask.com")
UsePage("WinTask - Automation software and Task Scheduler. Macro software with Macro Recorder")
Navigate("http://www.wintask.com/howitworks.php")
ClickHTMLElement("A[INNERTEXT= 'Contact Us']")
Note that the second UsePage function has been removed since the Navigate statement provides it's own synchronization.
Internet Explorer Keyboard Shortcuts
Internet Explorer provides keyboard shortcuts to navigate between web pages and between elements on the same web page. Navigation shortcuts can be used to avoid mouse clicks that may be dependent on screen or window size. Employing keyboard shortcuts can make the script more reliable across multiple workstations. Help topic Internet Explorer Keyboard Shortcuts provides a table of keyboard shortcuts and a short example of how an automation script can utilize them.