ActiveWindow
import {ActiveWindow} from 'cabbie-async';
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?): Promise<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(): Promise<void>
Close the current window
execute(script, args?): Promise<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(): Promise<Element>
Get the element on the page that currently has focus
getElement(selector, selectorType?): Promise<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?): Promise<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?): Promise<Array<Element>>
- selector
- string
- selectorType
- SelectorType
Get elements via a selector.
getElementsByTextContent(textContent, selector?, selectorType?): Promise<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(): Promise<{x:number, y:number}>
Get the position of a window
getSize(): Promise<{width:number, height:number}>
Get the size of a window
getSource(): Promise<string>
Get the current page source
getTitle(): Promise<string>
Get the current page title
getUrl(): Promise<string>
Get the current url that the browser is displaying
getWindowHandle(): Promise<WindowHandle>
Get a handle for the current window
goBackward(): Promise<void>
Navigate backwards in the browser history, if possible.
goForward(): Promise<void>
Navigate forwards in the browser history, if possible.
hasElement(selector, selectorType?): Promise<boolean>
- selector
- string
- selectorType
- SelectorType
Does a specific element exist?
maximize(): Promise<void>
Maximize a window
navigateTo(path): Promise<void>
- path
- string
Navigates the browser to the specified path
- if
path
begins with a "/" it is relative tooptions.base
- if
path
begins with "http" it is absolute - otherwise it is relative to the current path
position(x, y): Promise<void>
- x
- number
- y
- number
Position a window
refresh(): Promise<void>
Refreshes the browser
resize(width, height): Promise<void>
- width
- number
- height
- number
Get the size of a window
sendKeys(str): Promise<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(): Promise<Buffer>
Take a screenshot of the current page
This returns the result as a buffer containing the binary image data