Taiko
Documentation

Home / API Reference

evaluate

Evaluates script on element matching the given selector.

Examples

await evaluate(link("something"), (element) => element.style.backgroundColor)
await evaluate((element) => {
     element.style.backgroundColor = 'red';
})
await evaluate(() => {
  // Callback function have access to all DOM APIs available in the developer console.
  return document.title;
} )
let options = { args: [ '.main-content', {backgroundColor:'red'}]}

await evaluate(link("something"), (element, args) => {
     element.style.backgroundColor = args[1].backgroundColor;
     element.querySelector(args[0]).innerText = 'Some thing';
}, options)

Parameters


selector

Web element selector.


callback

callback method to execute on the element or root HTML element when selector is not provided.
NOTE : In callback, we can access only inline css not the one which are define in css files.


options

options.


options.waitForNavigation boolean

Wait for navigation after the click. Default navigation timeout is 15 seconds, to override pass { navigationTimeout: 10000 } in options parameter.

Default value
true

options.waitForStart number

wait for navigation to start. Accepts value in milliseconds.

Default value
100

options.navigationTimeout number

Navigation timeout value in milliseconds for navigation after click.

Default value
5000

options.args

Arguments to be passed to the provided callback.


options.waitForEvents Array<string>

Events available to wait for ['DOMContentLoaded', 'loadEventFired', 'networkAlmostIdle', 'networkIdle', 'firstPaint', 'firstContentfulPaint', 'firstMeaningfulPaint', 'targetNavigated']

Default value
[]

options.silent boolean

Set true to run script silently without printing messages.

Default value
false

Returns

Object with return value of callback given.

Promise<Object>