Mozmill Elements Library Object 编辑

Deprecated in Mozmill 2.0 - See finding mozmill elements instead.

The elements library object provides several mechanisms to reference objects for your Mozmill test. It is a wrapper to aid with identifying various DOM Nodes and controls that your test may encounter. Calling getNode() on any elements lib object will return you the contained DOM Node. The built-in Mozmill Inspector will aid you with finding the simplest mechanism to refer to any element that you want to interact with. Each method below is a constructor for an elementslib object.

Method overview

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

Methods

Elem()

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

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

elementslib Returns an elemntslib object

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

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

ID()

This constructs an elementslib 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.

elementslib 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

elementslib Returns an elemntslib object

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

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

// 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 = new elementslib.ID(controller.tabs.activeTab, 'bar');
controller.click(contentBar);

Link()

This constructs an elementslib 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.

elementslib 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

elementslib Returns an elemntslib 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 = new elementslib.Link(controller.tabs.activeTab, 'Wikipedia');
controller.click(link);

Name()

This constructs an elementslib 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.

elementslib 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

elementslib Returns an elemntslib 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 = new elementslib.Name(controller.tabs.activeTab, 'goButton');
controller.click(button);

XPath()

This constructs an elementslib 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.

elementslib 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

elementslib Returns an elemntslib 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 = new elementslib.XPath(controller.tabs.activeTab, "/html/body/span[@id='main']/span[@id='body']/center");
controller.waitForElement(e);

Lookup()

This constructs an elementslib 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.

elementslib 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

elementslib Returns an elemntslib 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 = new elementslib.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"})');
controller.click(lookupelement);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:103 次

字数:9803

最后编辑:8年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文