* {{> waitNumberOfVisibleElements }}
(locator, num, sec)
| 2352 | * {{> waitNumberOfVisibleElements }} |
| 2353 | */ |
| 2354 | async waitNumberOfVisibleElements(locator, num, sec) { |
| 2355 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 2356 | locator = new Locator(locator, 'css') |
| 2357 | let waiter |
| 2358 | const context = await this._getContext() |
| 2359 | if (locator.isCSS()) { |
| 2360 | const visibleFn = function (locator, num) { |
| 2361 | const els = document.querySelectorAll(locator) |
| 2362 | if (!els || els.length === 0) { |
| 2363 | return false |
| 2364 | } |
| 2365 | return Array.prototype.filter.call(els, el => el.offsetParent !== null).length === num |
| 2366 | } |
| 2367 | waiter = context.waitForFunction(visibleFn, { timeout: waitTimeout }, locator.value, num) |
| 2368 | } else { |
| 2369 | const visibleFn = function (locator, $XPath, num) { |
| 2370 | eval($XPath) |
| 2371 | return $XPath(null, locator).filter(el => el.offsetParent !== null).length === num |
| 2372 | } |
| 2373 | waiter = context.waitForFunction(visibleFn, { timeout: waitTimeout }, locator.value, $XPath.toString(), num) |
| 2374 | } |
| 2375 | return waiter.catch(err => { |
| 2376 | throw new Error(`The number of elements (${locator.toString()}) is not ${num} after ${waitTimeout / 1000} sec\n${err.message}`) |
| 2377 | }) |
| 2378 | } |
| 2379 | |
| 2380 | /** |
| 2381 | * {{> waitForClickable }} |
no test coverage detected