Class Alert

Represents a modal dialog such as {@code alert}, {@code confirm}, or {@code prompt}. Provides functions to retrieve the message displayed with the alert, accept or dismiss the alert, and set the response text (in the case of {@code prompt}).

extends

{webdriver.promise.Deferred}

Hierarchy

Index

Constructor methods

Properties

Methods

Constructor methods

constructor(driver: WebDriver, text: string): Alert

constructor

Parameters

  • driver: WebDriver

    The driver controlling the browser this alert is attached to.

  • text: string

    Either the message text displayed with this alert, or a promise that will be resolved to said text.

Returns

Alert

constructor(driver: WebDriver, text: Promise): Alert

Parameters

Returns

Alert

Properties

public promise: Promise

The consumer promise for this instance. Provides protected access to the callback registering functions.

type

{!webdriver.promise.Promise}

Methods

public accept(): Promise

Accepts this alert.

Returns

Promise

A promise that will be resolved when this command has completed.

public addBoth(callback: (value: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is either rejected or resolved. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call when this promise is either resolved or rejected. The function should expect a single argument: the resolved value or rejection error.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addCallback(callback: (value: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is successfully resolved. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addCallbacks(callback: (value: any) => any, errback: (error: any) => any, opt_self?: any): Promise

An alias for {@code webdriver.promise.Promise.prototype.then} that permits the scope of the invoked function to be specified. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • callback: (value: any) => any

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • errback: (error: any) => any

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public addErrback(errback: (error: any) => any, opt_self?: any): Promise

Registers a function to be invoked when this promise is rejected. This function is provided for backwards compatibility with the Dojo Deferred API.

Parameters

  • errback: (error: any) => any

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

  • opt_self?: any optional

    The object which |this| should refer to when the function is invoked.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.

public cancel(opt_reason?: any)

Cancels the computation of this promise's value and flags the promise as a rejected value.

Parameters

  • opt_reason?: any optional

    The reason for cancelling this promise.

public dismiss(): Promise

Dismisses this alert.

Returns

Promise

A promise that will be resolved when this command has completed.

public errback(opt_error?: any)

Parameters

  • opt_error?: any optional

public fulfill(opt_value?: any)

Resolves this promise with the given value. If the value is itself a promise and not a reference to this deferred, this instance will wait for it before resolving.

Parameters

  • opt_value?: any optional

    The resolved value.

public getText(): Promise

Retrieves the message text displayed with this alert. For instance, if the alert were opened with alert("hello"), then this would return "hello".

Returns

Promise

A promise that will be resolved to the text displayed with this alert.

public isPending(): boolean

Returns

boolean

Whether this promise's value is still being computed.

public reject(opt_error?: any)

Rejects this promise. If the error is itself a promise, this instance will be chained to it and be rejected with the error's resolved value.

Parameters

  • opt_error?: any optional

    The rejection reason, typically either a {@code Error} or a {@code string}.

public removeAll()

Removes all of the listeners previously registered on this deferred.

throws

{Error} If this deferred has already been resolved.

public sendKeys(text: string): Promise

Sets the response text on this alert. This command will return an error if the underlying alert does not support response text (e.g. window.alert and window.confirm).

Parameters

  • text: string

    The text to set.

Returns

Promise

A promise that will be resolved when this command has completed.

public then(opt_callback?: (value: any) => any, opt_errback?: (error: any) => any): Promise

Registers listeners for when this instance is resolved. This function most overridden by subtypes.

Parameters

  • opt_callback?: (value: any) => any optional

    The function to call if this promise is successfully resolved. The function should expect a single argument: the promise's resolved value.

  • opt_errback?: (error: any) => any optional

    The function to call if this promise is rejected. The function should expect a single argument: the rejection reason.

Returns

Promise

A new promise which will be resolved with the result of the invoked callback.