Finding Mozmill Elements

  • Revision slug: Mozmill/Finding_Mozmill_Elements
  • Revision title: Finding Mozmill Elements
  • Revision id: 92381
  • Created:
  • Creator: ahal
  • Is current revision? No
  • Comment 16 words added

Revision Content

This page is still under development and is only relevant to Mozmill 2.0 and later.

Mozmill provides several mechanisms to reference DOM nodes for your Mozmill test. The built-in Mozmill Inspector (not available in command line version) will aid you with finding the simplest mechanism to refer to any element that you want to interact with. Each method below returns a MozMillElement object which wraps the DOM node. To access the actual DOM node call MozMillElement.getNode(). Each method below is found in the 'findElement' namespace.

Method overview

MozMillElement Elem(in node node);
MozMillElement ID(in document doc, in string ID);
MozMillElement Link(in document doc, in string linkName);
MozMillElement XPath(in document doc, in string xpath);
MozMillElement Lookup(in document doc, in string lookup);

Methods

Elem()

This is the most basic constructor for a MozMillElement object. It allows you to wrap any DOM Node into a MozMillElement object. One of the most common use cases for this is to use the Menuing API as shown below.

MozMillElement Elem(
  in node node,
); 
Parameters
node
A DOM Node to wrap into a MozMillElement object for use in the controller APIs.
Return value

Elem returns a MozMillElement object

Example
// Wrapping a standard DOM Node into an elements lib object:
let e = findElement.Elem(document.getElementById('foo'));
e.click();

// Use in the controller menuing API (a very common use case for this constructor)
let closemenu = findElement.Elem(controller.menus.File['menu_close']);
closemenu.click();

ID()

This constructs a MozMillElement object by wrapping the DOM Node with the corresponding ID in the given document. There are several different document types that can be used from within a Mozmill test. See the examples below for a detailed description of their use. Note that the Mozmill Inspector will always provide you with the best shortcut to the document that the node is on, so if you use the Mozmill Inspector you will have these specified for you.

MozMillElement ID(
  in document document,
  in string id
); 
Parameters
document
A DOM Document that the node is in
id
The value of the id attribute of the element you want to wrap.
Return value

ID returns a MozMillElement object

Example
// Wrap an element that lives in the application UI space (i.e. chrome space)
let chromeFoo = findElement.ID(controller.window.document, 'foo');
chromeFoo.click();

// Wrap element foo that is in the rendered HTML page of the document (i.e. content space)
let contentFoo = findElement.ID(controller.window.content.document, 'foo');
contentFoo.click();

// If you want a very simple way to grab an element in the current tab, it is
// preferred to use controller.tabs.activeTab like so:
let contentBar = findElement.ID(controller.tabs.activeTab, 'bar');
contentBar.click();

Link()

This constructs a MozMillElement object by wrapping the DOM Node with the corresponding link title in the given document. This is useful for grabbing a reference to a hyperlink. Note that this uses the link title and not the link URL.

MozMillElement Link(
  in document document,
  in string link-name
); 
Parameters
document
A DOM Document that the node is in
link-name
The name of the element you want to wrap.
Return value

Link returns a MozMillElement object

Example
// Grabs a reference to the hyperlink with the given title.  So for a link like:
// <a href="http://wikipedia.org">Wikipedia</a> you would use:
let link = findElement.Link(controller.tabs.activeTab, 'Wikipedia');
link.click();

Name()

This constructs a MozMillElement object by wrapping the DOM Node with the corresponding name attribute in the given document. This is useful for grabbing a reference to a form control.

MozMillElement Name(
  in document document,
  in string name
); 
Parameters
document
A DOM Document that the node is in
name
The name of the element you want to wrap.
Return value

Name Returns a MozMillElement object

Example
// Grabs an input control with a given name.  The control would be coded like this:
// <input name="goButton" type="submit" value="Go"> etc.
let button = findElement.Name(controller.tabs.activeTab, 'goButton');
button.click();

XPath()

This constructs a MozMillElement object by wrapping the DOM Node referred to by the corresponding XPath in the given document. This is often used to reference attributes on web pages that do not have any standard identifiable attributes. The Mozmill Inspector can generate the proper XPath expression for you.

MozMillElement XPath(
  in document document,
  in string xpath
); 
Parameters
document
A DOM Document that the node is in
xpath
The xpath to the element you want to wrap.
Return value

XPath returns a MozMillElement object

Example
// Grabs a section of the page using XPath - this is useful to assert that a segment of the page has loaded, for example.
let element = findElement.XPath(controller.tabs.activeTab, "/html/body/span[@id='main']/span[@id='body']/center");
element.click();

Lookup()

This constructs a MozMillElement object by wrapping the DOM Node referenced by the corresponding Lookup expression in the given document. Lookup expressions are generated by the Mozmill Inspector to access anonymous nodes in the user interface. These are usually XBL controls.

MozMillElement Lookup(
  in document document,
  in string lookup
); 
Parameters
document
A DOM Document that the node is in
lookup
The lookup expression for the element (generated by the Inspector)
Return value

Lookup returns a MozMillElement object

Example
// This is a lookup expression, note that it can be broken up over several lines using the 
// JavaScript string concatenator operator, '+'
let lookupelement = findElement.Lookup(controller.window.document, 
                                           '/id("main-window")/id("navigator-toolbox")/id("nav-bar")/id("search-container")' +
                                           '/id("searchbar")/anon({"anonid":"searchbar-textbox"})/anon({"anonid":"searchbar-engine-button"})');
lookupelement.click();

Revision Source

<p><strong>This page is still under development and is only relevant to Mozmill 2.0 and later.</strong></p>
<p>Mozmill provides several mechanisms to reference DOM nodes for your Mozmill test. The built-in Mozmill Inspector (not available in command line version) will aid you with finding the simplest mechanism to refer to any element that you want to interact with. Each method below returns a MozMillElement object which wraps the DOM node. To access the actual DOM node call MozMillElement.getNode(). Each method below is found in the 'findElement' namespace.</p>
<h2>Method overview</h2>
<table class="standard-table"> <tbody> <tr> <td><code>MozMillElement <a href="#Elem.28.29">Elem</a>(in <a href="/en/DOM/Node" title="en/DOM/Node">node</a> node);</code></td> </tr> <tr> <td><code>MozMillElement <a href="#ID.28.29">ID</a>(in <a href="/en/DOM/document" title="en/DOM/document">document</a> doc, in string ID);</code></td> </tr> <tr> <td><code>MozMillElement <a href="#Link.28.29">Link</a>(in <a href="/en/DOM/document" title="en/DOM/document">document</a> doc, in string linkName);</code></td> </tr> <tr> <td><code>MozMillElement <a href="#XPath.28.29">XPath</a>(in <a href="/en/DOM/document" title="en/DOM/document">document</a> doc, in string xpath);</code></td> </tr> <tr> <td><code>MozMillElement <a href="#Lookup.28.29">Lookup</a>(in <a href="/en/DOM/document" title="en/DOM/document">document</a> doc, in string lookup);</code></td> </tr> </tbody>
</table>
<h2>Methods</h2>
<h3 name="Elem.28.29">Elem()</h3>
<p>This is the most basic constructor for a MozMillElement object. It allows you to wrap any DOM Node into a MozMillElement object. One of the most common use cases for this is to use the Menuing API as shown below.</p>
<pre>MozMillElement Elem(
  in <a href="https://developer.mozilla.org/en/DOM/Node" title="en/DOM/Node">node</a> node,
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>node</code></dt> <dd>A DOM Node to wrap into a MozMillElement object for use in the controller APIs.</dd>
</dl>
<h6>Return value</h6>
<p><code>Elem</code> returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// Wrapping a standard DOM Node into an elements lib object:
let e = findElement.Elem(document.getElementById('foo'));
e.click();

// Use in the controller menuing API (a very common use case for this constructor)
<span><span>let closemenu = findElement.Elem(controller.menus.File[</span><span class="string">'menu_close'</span><span>]);<br>closemenu.click();<br></span></span></pre>
<h3 name="ID.28.29">ID()</h3>
<p>This constructs a <code>MozMillElement</code> object by wrapping the DOM Node with the corresponding ID in the given document. There are several different document types that can be used from within a Mozmill test. See the examples below for a detailed description of their use. Note that the Mozmill Inspector will always provide you with the best shortcut to the document that the node is on, so if you use the Mozmill Inspector you will have these specified for you.</p>
<pre>MozMillElement ID(
  in <a href="https://developer.mozilla.org/en/DOM/document">document</a> document,
  in string id
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>document</code></dt> <dd>A DOM Document that the node is in</dd> <dt><code>id</code></dt> <dd>The value of the <code>id</code> attribute of the element you want to wrap.</dd>
</dl>
<h6>Return value</h6>
<p><code>ID</code> returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// Wrap an element that lives in the application UI space (i.e. chrome space)
let chromeFoo = findElement.ID(controller.window.document, 'foo');
chromeFoo.click();

// Wrap element foo that is in the rendered HTML page of the document (i.e. content space)
let contentFoo = findElement.ID(controller.window.content.document, 'foo');
contentFoo.click();

// If you want a very simple way to grab an element in the current tab, it is
// preferred to use controller.tabs.activeTab like so:
let contentBar = findElement.ID(controller.tabs.activeTab, 'bar');
contentBar.click();
</pre>
<h3 name="Link.28.29">Link()</h3>
<p>This constructs a <code>MozMillElement</code> object by wrapping the DOM Node with the corresponding link title in the given document. This is useful for grabbing a reference to a hyperlink. Note that this uses the link title and not the link URL.</p>
<pre>MozMillElement Link(
  in <a href="https://developer.mozilla.org/en/DOM/document">document</a> document,
  in string link-name
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>document</code></dt> <dd>A DOM Document that the node is in</dd> <dt><code>link-name</code></dt> <dd>The name of the element you want to wrap.</dd>
</dl>
<h6>Return value</h6>
<p><code>Link</code> returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// Grabs a reference to the hyperlink with the given title.  So for a link like:
// &lt;a href="http://wikipedia.org"&gt;Wikipedia&lt;/a&gt; you would use:
let link = findElement.Link(controller.tabs.activeTab, 'Wikipedia');
link.click();
</pre>
<h3 name="Name.28.29">Name()</h3>
<p>This constructs a <code>MozMillElement</code> object by wrapping the DOM Node with the corresponding name attribute in the given document. This is useful for grabbing a reference to a form control.</p>
<pre>MozMillElement Name(
  in <a href="https://developer.mozilla.org/en/DOM/document">document</a> document,
  in string name
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>document</code></dt> <dd>A DOM Document that the node is in</dd> <dt><code>name</code></dt> <dd>The name of the element you want to wrap.</dd>
</dl>
<h6>Return value</h6>
<p><code>Name</code> Returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// Grabs an input control with a given name.  The control would be coded like this:
// &lt;input name="goButton" type="submit" value="Go"&gt; etc.
let button = findElement.Name(controller.tabs.activeTab, 'goButton');
button.click();
</pre>
<h3 name="XPath.28.29">XPath()</h3>
<p>This constructs a <code>MozMillElement</code> object by wrapping the DOM Node referred to by the corresponding XPath in the given document. This is often used to reference attributes on web pages that do not have any standard identifiable attributes. The Mozmill Inspector can generate the proper XPath expression for you.</p>
<pre>MozMillElement XPath(
  in <a href="https://developer.mozilla.org/en/DOM/document">document</a> document,
  in string xpath
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>document</code></dt> <dd>A DOM Document that the node is in</dd> <dt><code>xpath</code></dt> <dd>The xpath to the element you want to wrap.</dd>
</dl>
<h6>Return value</h6>
<p><code>XPath</code> returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// Grabs a section of the page using XPath - this is useful to assert that a segment of the page has loaded, for example.
let element = findElement.XPath(controller.tabs.activeTab, "/html/body/span[@id='main']/span[@id='body']/center");
element.click();
</pre>
<h3 name="Lookup.28.29">Lookup()</h3>
<p>This constructs a <code>MozMillElement</code> object by wrapping the DOM Node referenced by the corresponding Lookup expression in the given document. Lookup expressions are generated by the Mozmill Inspector to access anonymous nodes in the user interface. These are usually <a href="/en/XBL" title="en/XBL">XBL controls</a>.</p>
<pre>MozMillElement Lookup(
  in <a href="https://developer.mozilla.org/en/DOM/document">document</a> document,
  in string lookup
); 
</pre>
<h6>Parameters</h6>
<dl> <dt><code>document</code></dt> <dd>A DOM Document that the node is in</dd> <dt><code>lookup</code></dt> <dd>The lookup expression for the element (generated by the Inspector)</dd>
</dl>
<h6>Return value</h6>
<p><code>Lookup</code> returns a MozMillElement object</p>
<h6>Example</h6>
<pre class="brush: js">// This is a lookup expression, note that it can be broken up over several lines using the 
// JavaScript string concatenator operator, '+'
let lookupelement = findElement.Lookup(controller.window.document, 
                                           '/id("main-window")/id("navigator-toolbox")/id("nav-bar")/id("search-container")' +
                                           '/id("searchbar")/anon({"anonid":"searchbar-textbox"})/anon({"anonid":"searchbar-engine-button"})');
lookupelement.click();
</pre>
Revert to this revision