FinderBase

FinderBase

Base class of Finder. Holds the lazily-evaluated condition chain.

Constructor

new FinderBase()

Source:

Methods

allowWindowClose() → {FinderBase}

Description:
  • Declare that the action closes the window itself, like clicking a link calling window.close(). Such an action can not return its result because the page is already gone, which is reported as an error like "Target page, context or browser has been closed". This method makes the action ignore that error.

Source:
Example
const newWin = await page.waitForNewWindow(()=>{ ... })
await newWin.page.find("a.close-link").allowWindowClose().click();
Returns:

new finder object

Type
FinderBase

clone(callback) → {Object}

Source:
Parameters:
Name Type Description
callback function

Optional. if callback function given, it is called with the cloned as argument

Returns:

cloned object

Type
Object

evaluate() → {Promise}

Description:
  • Evaluate this finder and resolve with the result (the match count, or the action result).

Source:
Returns:

Promise resolved in evaluated JavaScript code

Type
Promise

evaluateAction() → {Promise}

Description:
  • Evaluate as a action (used by click, fillIn, check, ...). The difference from evaluate() is how it behaves when an element is not found. When config.autoWaiting.enabled is false, throws "Element not found" error. When config.autoWaiting.enabled is true, retries until the target element exists, is visible and is not disabled. When config.slowMotion is over 0, wait that msec before running the action.

Source:
Returns:

Promise resolved in evaluated JavaScript code

Type
Promise

find() → {FinderBase}

Source:
Returns:

new finder object which have added conditions

Type
FinderBase

map() → {FinderBase}

Source:
Returns:

new finder object with added mapping function

Type
FinderBase

noWait() → {FinderBase}

Description:
  • Disable auto-waiting for this finder. The action is executed immediately even when config.autoWaiting.enabled is true. If target element is not found when called, throw exception.

Source:
Returns:

new finder object

Type
FinderBase

toJsCode(options) → {string}

Description:
  • generate and return javascript code for finding element by this finder object

Source:
Parameters:
Name Type Description
options object
Properties
Name Type Description
notFoundBehavior string

how the generated code behaves when no element matches: 'count' (default) return the number of matched elements (and it is zero) 'throw' throw "Element not found" 'marker' return the not-ready marker (for auto-waiting retries)

until string

used with notFoundBehavior: 'marker'. 'exist' (default) ready once the element exists 'actionable' ready once the element exists AND is visible and not disabled (includes 'exist')

Returns:
Type
string

waitTimeout(msec) → {FinderBase}

Description:
  • Override the auto-waiting timeout for this finder.

Source:
Parameters:
Name Type Description
msec number

timeout in milliseconds

Returns:

new finder object

Type
FinderBase

withRetry(opts) → {FinderBase}

Description:
  • Make evaluate() poll (retry) until the target condition is met, or the timeout elapses.

Source:
Parameters:
Name Type Description
opts object
Properties
Name Type Description
until string

what "ready" means. 'exist' (default): the element exists. 'actionable': the element exists AND is visible and not disabled (includes 'exist').

timeout number

msec. give up after this (default 5000)

interval number

msec. polling interval (default 100)

onTimeout function

optional. returns the Error to throw on timeout (default: Error('timeout'))

Returns:

new finder object

Type
FinderBase