document, navigation, and window Objects

The document and navigation objects can be used as an element in a compose statement.

document object

The document object exposes methods to interact with the DOM, such as waiting until its state is ready or checking the URL. It also exposes methods for frames.

Reference the document object inside a compose statement in JSON using this syntax:

{
  "element": "document",
  "apply": "getUrl"
}

Here are the supported methods for the document object. The return value is asynchronous. For example, in JavaScript, a Promise is returned.

Method Description Returns Example
waitFor<T> Waits for specified criteria to be satisfied. <T> beforeLoad
waitForDocumentReady() Waits for the document to be ready for JavaScript code to execute. boolean beforeLoad
containsElement(locator: Locator) Checks whether the document contains an element with a matching selector. boolean Explicit Waits
getUrl() Gets the URL of the document. string
enterFrame enters a frame or iframe element frame
enterFrameAndLoad enters a frame or iframe element and then loads a Page Object that is a new root frame, pageObject
exitFrame exits focus from a current frame or iframe
exitToParentFrame exits focus from a frame or iframe to the immediate parent frame

navigation object

The navigation object exposes methods for browser navigation, such as back and forward, as well as methods for managing multiple browser windows or tabs.

Reference the navigation object inside a compose statement in JSON using this syntax:

{
  "element": "navigation",
  "apply": "back"
}

Here are the supported methods for the navigation object.

Method Description Returns
back Browser navigates backward void
forward Browser navigates forward void
switchToWindow(url) Switches to the window navigated to the specified URL window
closeWindow(url) Closes the window navigated to the specified URL; if no URL is specified, closes the current window void
closeWindow() Closes the current window void
getWindowCount Gets the number of currently opened managed windows integer
currentWindow Gets the window with the current command context window
setupWaitForNewWindow Sets up a wait for a new window to appear after taking a subsequent action void
waitForNewWindow Waits for a new window to be opened and switches the command context to the new window; if called without a prior call to setupWaitForNewWindow, an exception is thrown window
waitForNewWindowAndLoad Waits for a new window to be opened, switches to it, and loads a Page Object that is a new root pageObject
switchToWindowAndLoad(url) Switches to the window navigated to the specified URL and loads a Page Object that is a new root pageObject

window object

The window object exposes methods for manipulating a single browser window or tab.

Here are the methods for the window object.

Method Description Returns
getRect Gets the rectangle of the window rect
setRect(rect) Sets the rectangle of the window void
close Closes the window void
getDocument Gets the document object associated with this window document