ActiveWindow

import {ActiveWindow} from 'cabbie-sync';

This is an object representing the currently active window. You can access the navigation for that window, touch and mouse objects for interacting via screen coordinates, and (most imporatantly) getElement and getElements.

Properties

alert: Alert

Get the Alert object.

frame: Frame

Get the Frame object.

mouse: GlobalMouse

Get the global-mouse object.

touch: GlobalTouch

The global-touch object.

Methods

asyncExecute(script, args?): void

script
string | Function
args
Array<any>

Execute a script asynchronously on the browser.

Source should be either a function body as a string or a function. Keep in mind that if it is a function it will not have access to any variables from the node.js process.

close(): void

Close the current window

execute(script, args?): any

script
string | Function
args
Array<any>

Execute a script on the browser and return the result.

Source should be either a function body as a string or a function. Keep in mind that if it is a function it will not have access to any variables from the node.js process.

getActiveElement(): Element

Get the element on the page that currently has focus

getElement(selector, selectorType?): Element

selector
string
selectorType
SelectorType

Get an element via a selector. Will throw an error if the element does not exist.

getElementByTextContent(textContent, selector?, selectorType?): Element

textContent
string
selector
string
selectorType
SelectorType

Get elements by its text content, optionally narrowed down using a selector.

N.B. this is much slower than getting elements by ID or css selector.

getElements(selector, selectorType?): Array<Element>

selector
string
selectorType
SelectorType

Get elements via a selector.

getElementsByTextContent(textContent, selector?, selectorType?): Array<Element>

textContent
string
selector
string
selectorType
SelectorType

Get elements by its text content, optionally narrowed down using a selector.

N.B. this is much slower than getting elements by ID or css selector.

getPosition(): {x:number, y:number}

Get the position of a window

getSize(): {width:number, height:number}

Get the size of a window

getSource(): string

Get the current page source

getTitle(): string

Get the current page title

getUrl(): string

Get the current url that the browser is displaying

getWindowHandle(): WindowHandle

Get a handle for the current window

goBackward(): void

Navigate backwards in the browser history, if possible.

goForward(): void

Navigate forwards in the browser history, if possible.

hasElement(selector, selectorType?): boolean

selector
string
selectorType
SelectorType

Does a specific element exist?

maximize(): void

Maximize a window

navigateTo(path): void

path
string

Navigates the browser to the specified path

  • if path begins with a "/" it is relative to options.base
  • if path begins with "http" it is absolute
  • otherwise it is relative to the current path

position(x, y): void

x
number
y
number

Position a window

refresh(): void

Refreshes the browser

resize(width, height): void

width
number
height
number

Get the size of a window

sendKeys(str): void

str
string | Array<string>

Type a string of characters into the browser

Note: Modifier keys is kept between calls, so mouse interactions can be performed while modifier keys are depressed.

takeScreenshot(): Buffer

Take a screenshot of the current page

This returns the result as a buffer containing the binary image data