Event Handler      


Receives a DOM event on the control.


function On<event>(inParam, eventObj)




The last parameter passed to RegisterForEvent.
The event object as passed by the browser. The object may vary between browsers.

Return Value

true on success, otherwise false.

Calling RegisterForEvent

If the event changes the DOM by adding elements to the control, you may need to call the _util object method, RegisterForEvent, to listen to events on the new elements. For example, opening a submenu may add new menu elements whose events must be recorded.

Order of Events

Your event handler is called before the browser handles the event. If the step to be recorded as a result of that event is dependent on the state of the control after the event, take into account that the application has not yet responded to this event.

For example, if your event handler is listening for a Click event on a toggle control, the step you will record depends on whether the Click event will cause the control to turn on or off. Since the browser has not yet handled the event, if the current state of the toggle is on, you will record a test step to turn the toggle off.

However, there may be cases where the browser already responded to an event that occurred before the event you are listening to, and has already changed the state of the control. When designing your event handler, be sure you understand the full sequence of events.


In this example, the event handlers will be passed a reference to the panel on which the event occurred.

function ConnectToEvents(elem)


    var stackPanels = getStackPanelItems(_elem);

    // Listen to click events on each of the panel headers in the StackPanel.

    for (var i = 0; i < stackPanels.length; i++)


        _util.RegisterForEvent(stackPanels[i], "onclick",

            "OnPanelSelect", stackPanels[i]);


    return true;


The event handler writes to the log files and calls the _util.Record method to write a test step.

function OnPanelSelect(panelHeader, eventObj)


    // Trim the new line before the title.

    var selectedPanelTitle = trim(panelHeader.innerText);

    _util.LogLine("Stack Panel mouse click event on panel " +




    // Create the test step:

    // Select <panel title>

    var arr = new Array();


    _util.Record("Select", toSafeArray(arr), 0);

    return true;