* {{> waitForEnabled }}
(locator, sec)
| 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 }} |
no test coverage detected