Let us consider a small example:
We are trying to automate an AJAXy mail client application which has an Inbox button, which when clicked, loads a part of the page, and this newly loaded content has a link 'Unread'.
When the first line is executed, the Inbox button gets clicked and the script has to wait till the relevant portions of the page load, before it can click 'Unread'.
To solve this, Sahi has a script parser which modifies this script to look something like this:
steps = new Array();
steps[steps.length] = "_click(_button('Inbox'));";
steps[steps.length] = "_click(_link('Unread'));";
And to execute these steps, it does:
var currentStep = 0;
if (currentStep == steps.length) return;