This page is currently under development and is only relevant to Mozmill 2.0 and later.
When you manipulate DOM elements with Mozmill, you are actually using a wrapper object that wraps around the DOM element node. This wrapper object contains all the methods that are relevant to the actual DOM node. For example, if you obtain a 'button' element, you can expect to find a 'button.click()' method. If you have a 'menulist' element, you can expect a 'menulist.select()' method. Note that the 'select' method will not be available on, for example, a 'button' element.
The wrapper objects are set up as a hierarchy which can be extended and customized as you see fit (see extending the mozmill element hierarchy). The base element contains all methods and properties that are common across all elements. Element types that have specific functionality sub-class this base class.
For more information on obtaining element references, see finding mozmill elements.
All sub-classes of elements have these methods:
element getNode(); |
string getInfo(); |
boolean exists(); |
boolean click(int left, int top); |
boolean doubleClick(int left, int top); |
boolean rightClick(int left, int top); |
boolean keypress(string keycode, object modifiers); |
boolean mouseDown(int button, int left, int top); |
boolean mouseOut(int button, int left, int top ); |
boolean mouseOver(int button, int left, int top ); |
boolean mouseUp(int button, int left, int top ); |
void waitForElement(int timeout, int interval); |
void waitThenClick(int timeout, int interval); |
boolean check(boolean state); |
boolean select(); |
boolean select(int index, string label, string value); |
boolean sendKeys(string text, object modifiers); |
Returns the actual wrapped DOM element.
element getNode();
A DOM element
var wrapper = findElement.ID(controller.document.window, 'elementID'); var element = wrapper.getNode(); controller.window.alert(element.localName); // Alerts the element's tag name
Returns information about the element.
string getInfo();
A string containing the locatorType and locator of the element
var element = findElement.ID(controller.document.window, 'elementID'); controller.window.alert(element.getInfo()); // Alerts the string "ID: elementID"
True if the element currently exists in the DOM, false otherwise. This function re-searches the DOM for the element given its locatorType and locator.
boolean exists();
true
if the element exists, otherwise false
var element = findElement.ID(controller.document.window, 'elementID'); // ... do some stuff that may cause element to disappear ... if (element.exists()) { element.click(); }
Fires a normal (left) click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean click( [in int left], [in int top] );
left
top
true
if the action succeeds, otherwise false
var button = findElement.ID(controller.tabs.activeTab, 'buttonID'); button.click(); // Or specify coordinates button.click(20, 10);
Fires a normal (left) double click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean doubleClick( [in int left], [in int top] );
left
top
true
if the action succeeds, otherwise false
var element = findElement.ID(controller.tabs.activeTab, 'elementName'); element.doubleClick(); // Or specify coordinates element.doubleClick(20, 10);
Fires a right click at the given element. You can optionally pass in coordinates to the function for where to click. The coordinates are relative to the element's bounding rectangle. With no coordinates specified, it clicks as 0, 0 on that rectangle (top left corner).
boolean rightClick( [in int left], [in int top] );
left
top
true
if the action succeeds, otherwise false
var element = findElement.ID(controller.window.document, 'elementID'); element.rightClick(); // Or specify coordinates element.rightClick(20, 10);
Sends a key event for the given keycode. The modifiers are a JSON object that specifies what key modifiers should be pressed in conjunction with the given key code. The available attribute names for the modifier object are: ctrlKey, altKey, shiftKey, metaKey, and accelKey. Try to avoid the usage of ctrlKey and metaKey if the shortcut is a combination of Ctrl (Windows/Linux) and Cmd (Mac); use accelKey instead which will work regardless of which operating system your test is executing on.
boolean keypress( in string keycode, [in object modifiers] );
keycode
modifiers
true
if the action succeeds, otherwise false
// Fire an escape keystroke at an element: var element = findElement.ID(controller.window.document, 'elementID'); element.keypress('VK_ESCAPE'); // Fire a simple keystroke at an element using the control/command and shift keys element.keypress('b', {shiftKey: true, accelKey: true});
Simulates the left button being depressed on the mouse when the mouse is over the given element.
boolean mouseDown( in int button, [in int left], [in int top] );
button
left
top
true
if the action succeeds, otherwise false
var element = findElement.ID(controller.window.document, 'elementID'); element.mouseDown(1); // middle button down
Simulates the mouse leaving the area over an event without clicking on it. If the element is out of view, the element will be scrolled into view before initiating the mouseOut.
boolean mouseOut( [in int button], [in int left], [in int top] );
button
left
top
true
if the action succeeds, otherwise false
var element = findElement.ID(controller.window.document, 'elementID'); element.mouseOut();
Simulates the mouse entering the area over an event without clicking on it. If the element is out of view, the element will be scrolled into view before initiating the mouseOver
boolean mouseOver( [in int button], [in int left], [in int top] );
button
left
top
true
if the action succeeds, otherwise false
var element = findElement(controller.window.document, 'elementID'); element.mouseOver();
Simulates the button being released on the mouse when the mouse is over the given element.
boolean mouseUp( [in int button], [in int left], [in int top] );
button
left
top
true
if the action succeeds, otherwise false
var element = findElement.ID(controller.window.document, 'elementID'); element.mouseUp();
Waits for the "element" to appear in the user interface (for instance, if you wanted to wait for part of a page or dialog to load). It checks for "element" every "interval" milliseconds, and gives up if "timeout" milliseconds have passed without the "element" appearing, causing the test to fail. If you accept the defaults, it will check for the element every 100ms and will throw an error if 5 seconds pass without the element appearing.
void waitForElement( [in int timeout], [in int interval] );
timeout
interval
None
var element = findElement.ID(controller.window.document, 'elementID'); element.waitForElement();
Waits for the "element" to appear in the user interface. It checks for "element" every "interval" milliseconds, and gives up if "timeout" milliseconds have passed without the "element" appearing, causing the test to fail. Once "element" appears, a click event is immediately fired at it. This is a simple shortcut API for the common pattern of waiting for an element to appear before firing a click event on it. It is the equivalent of calling 'waitForElement' followed by 'click'. Default timeout is 5s.
void waitThenClick( [in int timeout], [in int interval] );
timeout
interval
None
var element = findElement.ID(controller.window.document, 'elementID'); element.waitThenClick();
Fires a click at the given checkbox element to ensure it is either checked or not.
boolean check( in boolean state );
state
true
if the action succeeds, otherwise false
var checkbox = findElement(controller.window.document, 'checkboxID'); checkbox.check(true);
Selects the given radio button by firing a click at it.
boolean select();
true
if the action succeeds, otherwise false
var radio = findElement(controller.window.document, 'radioID'); radio.select();
Handles selecting an option from a menupopup or an HTML select element. The "element" corresponds to the list. There are multiple ways to select from such a list, either by "index", by "label", or by the "value" associated with that option.
boolean select( in int index, in string label, in string value );
index
null
if you do not wish to specify an index. -1 will reset the selection.label
null.
value
null.
true
if the action succeeds, otherwise false
// Select only using the index var list = findElement(controller.window.document, 'listID'); list.select(2); // Select using the label list.select(null, 'listItemLabel');
Types a string of text at the given element. The modifiers are a JSON object that specifies what key modifiers should be pressed in conjunction with the given key code. The available attribute names for the modifier object are: ctrlKey, altKey, shiftKey, metaKey, and accelKey. Try to avoid the usage of ctrlKey and metaKey if the shortcut is a combination of Ctrl (Windows/Linux) and Cmd (Mac); use accelKey instead which will work regardless of which operating system your test is executing on.
boolean sendKeys( in string text, [in object modifiers] );
text
modifiers
true
if the action succeeds, otherwise false
var textbox = findElement.ID(controller.window.document, 'textboxID'); textbox.sendKeys('some text to type');