Skip to content

evaluate()

Evaluates script on element matching the given selector.

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)
NameTypeDescription
selectorselector | stringWeb element selector.
callbackfunctioncallback 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.
optionsObjectoptions. Default: {}.
options.waitForNavigationbooleanWait for navigation after the click. Default navigation timeout is 15 seconds, to override pass { navigationTimeout: 10000 } in options parameter. Default: true.
options.waitForStartnumberwait for navigation to start. Accepts value in milliseconds. Default: 100.
options.navigationTimeoutnumberNavigation timeout value in milliseconds for navigation after click. Default: 5000.
options.argsArrayArguments to be passed to the provided callback.
options.waitForEventsArrayEvents available to wait for [‘DOMContentLoaded’, ‘loadEventFired’, ‘networkAlmostIdle’, ‘networkIdle’, ‘firstPaint’, ‘firstContentfulPaint’, ‘firstMeaningfulPaint’, ‘targetNavigated’] Default: [].
options.silentbooleanSet true to run script silently without printing messages. Default: false.
TypeDescription
Promise<Object>Object with return value of callback given.