MCPcopy
hub / github.com/codeceptjs/CodeceptJS / $

Method $

lib/element/WebElement.js:395–428  ·  view source on GitHub ↗

* Find first child element matching the locator * @param {string|Object} locator Element locator * @returns {Promise } WebElement instance or null if not found

(locator)

Source from the content-addressed store, hash-verified

393 * @returns {Promise<WebElement|null>} WebElement instance or null if not found
394 */
395 async $(locator) {
396 let childElement
397
398 switch (this.helperType) {
399 case 'playwright':
400 // Playwright Locator objects use locator() method
401 if (this.element.locator) {
402 const childLocator = this.element.locator(this._normalizeLocator(locator))
403 // Get the element handle from the locator
404 try {
405 childElement = await childLocator.elementHandle()
406 } catch (e) {
407 return null
408 }
409 } else {
410 childElement = await this.element.$(this._normalizeLocator(locator))
411 }
412 break
413 case 'webdriver':
414 try {
415 childElement = await this.element.$(this._normalizeLocator(locator))
416 } catch (e) {
417 return null
418 }
419 break
420 case 'puppeteer':
421 childElement = await this.element.$(this._normalizeLocator(locator))
422 break
423 default:
424 throw new Error(`Unsupported helper type: ${this.helperType}`)
425 }
426
427 return childElement ? new WebElement(childElement, this.helper) : null
428 }
429
430 /**
431 * Find all child elements matching the locator

Callers 15

inIframeMethod · 0.80
_setPageMethod · 0.80
_withinEndMethod · 0.80
proceedSeeFunction · 0.80
targetCreatedHandlerFunction · 0.80
makeTouchActionMethod · 0.80
tapMethod · 0.80
swipeMethod · 0.80
clickMethod · 0.80
targetCreatedHandlerFunction · 0.80
findMarkedFunction · 0.80

Calls 1

_normalizeLocatorMethod · 0.95

Tested by

no test coverage detected