MCPcopy Index your code
hub / github.com/codeceptjs/CodeceptJS / waitNumberOfVisibleElements

Method waitNumberOfVisibleElements

lib/helper/Playwright.js:3246–3273  ·  view source on GitHub ↗

* {{> waitNumberOfVisibleElements }} *

(locator, num, sec)

Source from the content-addressed store, hash-verified

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 }}

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected