MCPcopy
hub / github.com/codeceptjs/CodeceptJS / waitForEnabled

Method waitForEnabled

lib/helper/Puppeteer.js:2293–2318  ·  view source on GitHub ↗

* {{> waitForEnabled }}

(locator, sec)

Source from the content-addressed store, hash-verified

2291 * {{> waitForEnabled }}
2292 */
2293 async waitForEnabled(locator, sec) {
2294 const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout
2295 locator = new Locator(locator, 'css')
2296 await this.context
2297 let waiter
2298 const context = await this._getContext()
2299 if (locator.isCSS()) {
2300 const enabledFn = function (locator) {
2301 const els = document.querySelectorAll(locator)
2302 if (!els || els.length === 0) {
2303 return false
2304 }
2305 return Array.prototype.filter.call(els, el => !el.disabled).length > 0
2306 }
2307 waiter = context.waitForFunction(enabledFn, { timeout: waitTimeout }, locator.value)
2308 } else {
2309 const enabledFn = function (locator, $XPath) {
2310 eval($XPath)
2311 return $XPath(null, locator).filter(el => !el.disabled).length > 0
2312 }
2313 waiter = context.waitForFunction(enabledFn, { timeout: waitTimeout }, locator.value, $XPath.toString())
2314 }
2315 return waiter.catch(err => {
2316 throw new Error(`element (${locator.toString()}) still not enabled after ${waitTimeout / 1000} sec\n${err.message}`)
2317 })
2318 }
2319
2320 /**
2321 * {{> waitForValue }}

Calls 4

_getContextMethod · 0.95
isCSSMethod · 0.80
waitForFunctionMethod · 0.45
toStringMethod · 0.45

Tested by

no test coverage detected