QF-TestFree Trial

58.10.4 The DomNode class

The DomNode class is derived from Node and also resides in the package de.qfs.apps.qftest.client.web.dom. In addition to the methods defined in the Node class and explained above, DomNode provides the following:

Object callJS(String code)

Execute some JavaScript code in a function in the context of this node's document. This often works even if the call of eval() is restricted by a Content Security Policy (CSP).

Parameters
code
The script to execute. Use _qf_node as the reference for the HTML element.
Returns
Whatever the code returns explicitely using a return statement, converted to the proper object type. Even returning a DOM node, frame or document works.
Object evalJS(String script)

Evaluate some JavaScript code in the context of this node's document by calling window.eval().

Note In most cases, the method callJS should be used instead, since eval() might be restricted by the document's Content Security Policy (CSP).

Parameters
script
The script to execute. Use _qf_node as the reference for the HTML element.
Returns
Whatever the script returns, converted to the proper object type. Even returning a DOM node, frame or document works.
DomNode[] getAllByCSS(String css)

Get all nodes, which are determined via CSS-selectors.

Parameters
css
CSS-selector starting from that node.
Returns
An array of all found nodes or null.
DomNode[] getAllByXPath(String xpath)

Get all nodes, which are determined via XPath.

Parameters
xpath
XPath starting from that node.
Returns
An array of all found nodes or null.
DomNode getByCSS(String css)

Get a node, which is determined via a CSS-selector.

Parameters
css
CSS-selector starting from that node.
Returns
The found node or null.
DomNode getByXPath(String xpath)

Get a node, which is determined via XPath.

Parameters
xpath
XPath starting from that node.
Returns
The found node or null.
Node[] getChildrenByTagName(String tagName)

Get all direct child nodes of this node with a given tag name.

Parameters
tagName
The tag name to look for.
Returns
An array of child nodes with the given tag name. If none are found, an empty array is returned.
String getId()

Get the cached ID of the node which may have been processed by an IdResolver as described in "The IdResolver interface". The original, unmodified 'ID' attribute is available via getAttribute("id").

Returns
The cached ID of the node.
int[] getLocationOnScreen()

Get the location and size of the node relative to desktop.

Returns
The node's geometry in the form [x, y, width, height].
boolean hasCSSClass(String cl)

Check, whether the node has a specified css-class.

Parameters
cl
The name of the css-class.
Returns
True, if the node has this css-class, otherwise false.
boolean hasFocus()

Test whether the node has the keyboard focus.

Returns
True if the node has the keyboard focus.
boolean isShowing()

Test whether the node is visible or can be made visible by scrolling.

Returns
True if the node is visible.
void requestFocus()

Tell the node to request the keyboard focus. This is a best-effort implementation. Whether the node actually receives the keyboard focus depends on the browser and operating system settings.

void scrollVisible()

Try to scroll the page or a frame so as to make the node fully visible. This is a best effort implementation. Whether the node can actually be made visible depends on the browser and operating system settings.

void setAttribute(String name, String value)

Set an attribute value on the node.

Parameters
name
The name of the attribute.
value
The value to set.
void toJS(String name)

Set a JavaScript variable in the context of this node's document to this node.

Parameters
name
The name of the variable to set.