* {{> waitForValue }}
(field, value, sec)
| 2321 | * {{> waitForValue }} |
| 2322 | */ |
| 2323 | async waitForValue(field, value, sec) { |
| 2324 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 2325 | const locator = new Locator(field, 'css') |
| 2326 | await this.context |
| 2327 | let waiter |
| 2328 | const context = await this._getContext() |
| 2329 | if (locator.isCSS()) { |
| 2330 | const valueFn = function (locator, value) { |
| 2331 | const els = document.querySelectorAll(locator) |
| 2332 | if (!els || els.length === 0) { |
| 2333 | return false |
| 2334 | } |
| 2335 | return Array.prototype.filter.call(els, el => (el.value.toString() || '').indexOf(value) !== -1).length > 0 |
| 2336 | } |
| 2337 | waiter = context.waitForFunction(valueFn, { timeout: waitTimeout }, locator.value, value) |
| 2338 | } else { |
| 2339 | const valueFn = function (locator, $XPath, value) { |
| 2340 | eval($XPath) |
| 2341 | return $XPath(null, locator).filter(el => (el.value || '').indexOf(value) !== -1).length > 0 |
| 2342 | } |
| 2343 | waiter = context.waitForFunction(valueFn, { timeout: waitTimeout }, locator.value, $XPath.toString(), value) |
| 2344 | } |
| 2345 | return waiter.catch(err => { |
| 2346 | const loc = locator.toString() |
| 2347 | throw new Error(`element (${loc}) is not in DOM or there is no element(${loc}) with value "${value}" after ${waitTimeout / 1000} sec\n${err.message}`) |
| 2348 | }) |
| 2349 | } |
| 2350 | |
| 2351 | /** |
| 2352 | * {{> waitNumberOfVisibleElements }} |
no test coverage detected