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.

MethodDescriptionReturnsExample
waitFor<T>Waits for specified criteria to be satisfied.<T>beforeLoad
waitForDocumentReady()Waits for the document to be ready for JavaScript code to execute.booleanbeforeLoad
containsElement(locator: Locator)Checks whether the document contains an element with a matching selector.booleanGuide: Explicit Waits
getUrl()Gets the URL of the document.string
enterFrameenters a frame or iframe elementframe
enterFrameAndLoadenters a frame or iframe element and then loads a Page Object that is a new rootframe, pageObject
exitFrameexits focus from a current frame or iframe
exitToParentFrameexits focus from a frame or iframe to the immediate parent frame

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.

MethodDescriptionReturns
backBrowser navigates backwardvoid
forwardBrowser navigates forwardvoid
getWindowCountGets the number of currently opened managed windowsinteger
currentWindowGets the window with the current command contextwindow
setupWaitForNewWindowSets up a wait for a new window to appear after taking a subsequent actionvoid
waitForNewWindowWaits 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 thrownwindow
waitForNewWindowAndLoadWaits for a new window to be opened, switches to it, and loads a Page Object that is a new rootpageObject
switchToWindow(url)Switches to the window navigated to the specified URLwindow
switchToWindowAndLoad(url)Switches to the window navigated to the specified URL and loads a Page Object that is a new rootpageObject
closeWindow(url)Closes the window navigated to the specified URL; if no URL is specified, closes the current windowvoid

window object

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

Here are the methods for the window object.

MethodDescriptionReturns
getRectGets the rectangle of the windowrect
setRect(rect)Sets the rectangle of the windowvoid
closeCloses the windowvoid
getDocumentGets the document object associated with this windowdocument