* Find first child element matching the locator * @param {string|Object} locator Element locator * @returns {Promise } WebElement instance or null if not found
(locator)
| 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 |
no test coverage detected