* {{> waitNumberOfVisibleElements }} *
(locator, num, sec)
| 3244 | * |
| 3245 | */ |
| 3246 | async waitNumberOfVisibleElements(locator, num, sec) { |
| 3247 | const waitTimeout = sec ? sec * 1000 : this.options.waitForTimeout |
| 3248 | locator = new Locator(locator, 'css') |
| 3249 | |
| 3250 | let waiter |
| 3251 | const context = await this._getContext() |
| 3252 | if (locator.isCSS()) { |
| 3253 | const visibleFn = function ([locator, num]) { |
| 3254 | const els = document.querySelectorAll(locator) |
| 3255 | if (!els || els.length === 0) { |
| 3256 | return false |
| 3257 | } |
| 3258 | return Array.prototype.filter.call(els, el => el.offsetParent !== null).length === num |
| 3259 | } |
| 3260 | waiter = context.waitForFunction(visibleFn, [locator.value, num], { timeout: waitTimeout }) |
| 3261 | } else { |
| 3262 | const visibleFn = function ([locator, $XPath, num]) { |
| 3263 | eval($XPath) |
| 3264 | return $XPath(null, locator).filter(el => el.offsetParent !== null).length === num |
| 3265 | } |
| 3266 | waiter = context.waitForFunction(visibleFn, [locator.value, $XPath.toString(), num], { |
| 3267 | timeout: waitTimeout, |
| 3268 | }) |
| 3269 | } |
| 3270 | return waiter.catch(err => { |
| 3271 | throw new Error(`The number of elements (${locator.toString()}) is not ${num} after ${waitTimeout / 1000} sec\n${err.message}`) |
| 3272 | }) |
| 3273 | } |
| 3274 | |
| 3275 | /** |
| 3276 | * {{> waitForClickable }} |
nothing calls this directly
no test coverage detected