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
| Name | Type | Description |
|---|---|---|
selector |
selector | string | Web element selector. |
callback |
function | 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 |
Object | options. Default: {}. |
options.waitForNavigation |
boolean | Wait for navigation after the click. Default navigation timeout is 15 seconds, to override pass { navigationTimeout: 10000 } in options parameter. Default: true. |
options.waitForStart |
number | wait for navigation to start. Accepts value in milliseconds. Default: 100. |
options.navigationTimeout |
number | Navigation timeout value in milliseconds for navigation after click. Default: 5000. |
options.args |
Array | Arguments to be passed to the provided callback. |
options.waitForEvents |
Array | Events available to wait for [‘DOMContentLoaded’, ‘loadEventFired’, ‘networkAlmostIdle’, ‘networkIdle’, ‘firstPaint’, ‘firstContentfulPaint’, ‘firstMeaningfulPaint’, ‘targetNavigated’] Default: []. |
options.silent |
boolean | Set true to run script silently without printing messages. Default: false. |
Returns
| Type | Description |
|---|---|
| Promise<Object> | Object with return value of callback given. |