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

Method grabTextFrom

lib/helper/Playwright.js:2706–2730  ·  view source on GitHub ↗

* {{> grabTextFrom }} *

(locator)

Source from the content-addressed store, hash-verified

2704 *
2705 */
2706 async grabTextFrom(locator) {
2707 const roleElements = await handleRoleLocator(this.page, locator)
2708 if (roleElements && roleElements.length > 0) {
2709 const text = await roleElements[0].textContent()
2710 assertElementExists(text, JSON.stringify(locator))
2711 this.debugSection('Text', text)
2712 return text
2713 }
2714
2715 const locatorObj = new Locator(locator, 'css')
2716
2717 locator = this._contextLocator(locator)
2718 try {
2719 const text = await this.page.textContent(locator)
2720 assertElementExists(text, locator)
2721 this.debugSection('Text', text)
2722 return text
2723 } catch (error) {
2724 // Convert Playwright timeout errors to ElementNotFound for consistency
2725 if (error.message && error.message.includes('Timeout')) {
2726 throw new ElementNotFound(locator, 'text')
2727 }
2728 throw error
2729 }
2730 }
2731
2732 /**
2733 * {{> grabTextFromAll }}

Callers

nothing calls this directly

Calls 4

_contextLocatorMethod · 0.95
handleRoleLocatorFunction · 0.85
includesMethod · 0.80
assertElementExistsFunction · 0.70

Tested by

no test coverage detected